Imports System.IO
Imports System.Data.SqlClient
Imports System
Imports System.Text
Imports System.Data.Odbc

Public Class FrmDiagnosis
    Dim parentnode As TreeNode
    Dim DSNEvent As DataSet
    Dim DSNInvestigation As DataSet
    Dim DSNHistory As DataSet
    Dim DSNHistology As DataSet
    Dim DSNTxRecommendation As DataSet
    Dim DSNPatient As DataSet
    Dim currentselectedtab As String
    Dim vHisto_ID As String = ""
    Dim vHistoIDold As String = ""
    Dim vNeoAdj_ID As String = ""
    Dim currentEventStatus As String
    Dim gv_isedit As String 'added by cherwei to insert, can be remove

    Private recurrenceBindingSource1 As New DataTable()
    Private recurrenceDataAdapter As New SqlDataAdapter()

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'If TreeView2.SelectedNode Is Nothing Then
        GV_SELECTED_EVENTID = ""

        'line section closed for new procedure
        'Else
        'GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        'End If

        'Dim oFrmEvent As New FrmEvent()
        'oFrmEvent.Show()
        FrmEvent.Close()
        FrmEvent.Show()
        FrmEvent.Focus()

    End Sub
    Private Sub ListPatientDiagnosis()


        Dim DSNWind As DataSet
        'Dim CNnwind As New SqlClient.SqlConnection("DATA SOURCE=(local);USER ID=sa;PASSWORD=lifebook;INITIAL CATALOG=B2B;") '<==== CHANGE HERE 
        Dim CNnwind As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAEvent As New SqlClient.SqlDataAdapter("SELECT Event_msg, Event_ID,Status FROM Event where status <>'D' and pt_id1 = '" & GV_CUR_PATID & "'  order by date_tb " & GV_EVENT_SORT, CNnwind)
        Dim DAHistory As New SqlClient.SqlDataAdapter("SELECT HISTORY_MSG, EVENT_ID, PT_Id1, HISTORY_ID, Status FROM HISTORY where  status <>'D'  and EVENT_ID in (select EVENT_ID from Event WHERE  status <>'D' and pt_id1 =  '" & GV_CUR_PATID & "')", CNnwind)
        Dim DAInvestigation As New SqlClient.SqlDataAdapter("SELECT INV_MSG, EVENT_ID, PT_Id1, INV_ID , Status FROM Investigation where status <>'D' and  EVENT_ID in (select EVENT_ID from Event WHERE  status <>'D' and PT_Id1 = '" & GV_CUR_PATID & "')", CNnwind)
        Dim DAHistology As New SqlClient.SqlDataAdapter("SELECT Histology_msg, EVENT_ID, PT_Id1, Histo_ID , Status FROM Histology where status <>'D' and EVENT_ID in (select EVENT_ID from Event WHERE status <>'D' and PT_Id1 = '" & GV_CUR_PATID & "')", CNnwind)
        Dim DAHistology_Neoadj As New SqlClient.SqlDataAdapter("Select Neoadj_Msg, EVENT_ID, PT_Id1,Neoadj_ID,Histo_ID , Status from Neoadj where  status <>'D' and Histo_ID in (SELECT Histo_ID FROM Histology where EVENT_ID in (select EVENT_ID from Event WHERE PT_Id1 =  '" & GV_CUR_PATID & "'))", CNnwind)
        Dim DAHistology_Recurrence As New SqlClient.SqlDataAdapter("Select PriorTx_Msg, EVENT_ID, PT_Id1,PriorTx_ID,PT_Id1,Histo_ID , Status from PriorTx where status <>'D' and Histo_ID in (SELECT Histo_ID FROM Histology where EVENT_ID in (select EVENT_ID from Event WHERE PT_Id1 =  '" & GV_CUR_PATID & "'))", CNnwind)
        Dim DATxRecommendation As New SqlClient.SqlDataAdapter("SELECT Tx_msg, EVENT_ID, PT_Id1, recom_id , Status FROM recom where  status <>'D' and EVENT_ID in (select EVENT_ID from Event WHERE  status <>'D' and PT_Id1 =  '" & GV_CUR_PATID & "')", CNnwind)

        DSNWind = New DataSet()
        CNnwind.Open()
        DSNWind.Clear()
        DAEvent.Fill(DSNWind, "dtEvent")
        DAHistory.Fill(DSNWind, "dtHistory")
        DAInvestigation.Fill(DSNWind, "dtInvestigation")
        DAHistology.Fill(DSNWind, "dtHistology")
        DAHistology_Neoadj.Fill(DSNWind, "dtHistology_Neoadj")
        DAHistology_Recurrence.Fill(DSNWind, "dtHistology_Recurrence")
        DATxRecommendation.Fill(DSNWind, "dtTxRecommendation")

        ''Close the connection to the data store; free up the resources
        CNnwind.Close()

        'Create a data relation object to facilitate the relationship
        DSNWind.Relations.Add("EventToHis", DSNWind.Tables("dtEvent").Columns("Event_ID"), DSNWind.Tables("dtHistory").Columns("Event_ID"))
        DSNWind.Relations.Add("EventToInv", DSNWind.Tables("dtEvent").Columns("Event_ID"), DSNWind.Tables("dtInvestigation").Columns("Event_ID"))
        DSNWind.Relations.Add("EventToHistology", DSNWind.Tables("dtEvent").Columns("Event_ID"), DSNWind.Tables("dtHistology").Columns("Event_ID"))
        DSNWind.Relations.Add("HistologyToNeoadj", DSNWind.Tables("dtHistology").Columns("Histo_ID"), DSNWind.Tables("dtHistology_Neoadj").Columns("Histo_ID"))
        DSNWind.Relations.Add("HistologyToRecurrence", DSNWind.Tables("dtHistology").Columns("Histo_ID"), DSNWind.Tables("dtHistology_Recurrence").Columns("Histo_ID"))
        DSNWind.Relations.Add("EventToTxRecommendation", DSNWind.Tables("dtEvent").Columns("Event_ID"), DSNWind.Tables("dtTxRecommendation").Columns("Event_ID"))
        '''''''''''''''''''''''''
        Try
            TreeView2.Nodes.Clear()
        Catch ex As Exception

        End Try

        Dim vColor As String
        Dim vTreeColor As Color

        Dim i, n As Integer
        Dim parentrow As DataRow
        Dim ParentTable As DataTable
        ParentTable = DSNWind.Tables("dtEvent")

        For Each parentrow In ParentTable.Rows

            Dim parentnodeStatuts As TreeNode
            parentnode = New TreeNode(parentrow.Item(0))
            parentnodeStatuts = New TreeNode(parentrow.Item(0))
            TreeView2.Nodes.Add(parentnode)

            ' level 0 .. event id
            parentnode.Name = parentrow("Event_ID")

            'assign parentnode to tabpages
            'TabControl1.TabPages.Add(parentnode.Name)

            If parentrow("Status") = "P" Then
                vTreeColor = Color.Orange
            Else
                vTreeColor = Color.Black
            End If
            parentnode.ForeColor = vTreeColor
            ''''populate child'''''
            '''''''''''''''''''''''
            Dim childrow As DataRow
            Dim childnode As TreeNode
            childnode = New TreeNode()


        Next parentrow
        TreeView2.ExpandAll()


        'Dim selectedNodename As String = TreeView2.SelectedNode.Text

        'Dim selectedNodename1 As String = TreeView2.Nodes.Item(0).ToString()
        'Dim selectedNodename2 As String = TreeView2.Nodes.Item(1).ToString()
        'Dim selectedNodename3 As String = TreeView2.Nodes.Item(2).ToString()
        'Dim selectedNodename4 As String = TreeView2.Nodes.Item(3).ToString()
        'Dim selectedNodename5 As String = TreeView2.Nodes.Item(4).ToString()
        'Dim selectednodename As String = 'TreeView2.Parent

        'selectedNodename1 = selectedNodename1 + " this is a test"
        'TreeView2.SelectedNode
        'TreeView2.Nodes(1).child()
        'TreeView2.SelectedNode.Level = 2

        'DisplayChildNodesText(TreeView2.Nodes(1))
        'GetChildren(TreeView2.SelectedNode)

        'GetChildren()

        'Dim n As Node, aNodes As String, lLevel As Long
        'n = TreeView1.selectedItem
        'If n.children Then aNodes = "+" & n.Text
        'ModifyCollection(TreeView2.,delegate(TreeNodeCollection c

        'Dim childNodeTemp As TreeNode
        'childNodeTemp = TreeView2.Nodes(0).Nodes(1)

        'tnSelectedNode = TreeView2.GetNodeFromIndex(treeView1.SelectedNodeIndex)
        Me.LoadCT()
        Me.LoadCXR()
        Me.LoadBone()
        Me.LoadFamilyHistory()
        Me.LoadMenstrualStatus()

        Me.LoadExtChestWall()
        Me.LoadClinAxillaryLN()
        Me.LoadTypeBiopsy()
        Me.LoadHistoDx()
        Me.LoadTypeSurg()
        Me.LoadReconstruction()
        Me.LoadHistoType()
        Me.LoadHistoGrade()
        Me.LoadDCIS()
        Me.LoadLymhovascular()
        Me.LoadMargin_invasive()
        Me.LoadMarginDCIS()
        Me.LoadRadialMargin()
        Me.LoadSentinel_LN()
        Me.LoadSentinelLNPolarity()
        Me.LoadER_Status()
        Me.LoadPR_Status()
        Me.LoadErbB2()
        Me.LoadN_Status()
        Me.LoadM_Status()
        Me.LoadcT_Status()

        Me.LoadDoctor()
        Me.LoadCaseType()
        Me.LoadLaterality()

        GV_SELECTED_DATAENTRY_MODE = "Data_entry"
        Me.LoadBTB_Recommend()
        Try
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        Catch ex As Exception
            'if there is no event created yet
            GV_SELECTED_EVENTID = ""

        End Try

        Me.displayPatientData(GV_SELECTED_EVENTID)

        'Dim childrow1 As DataRow
        'For Each childrow1 In parentrow.GetChildRows("EventToInv")
        'parentnode.Nodes.Remove(childrow1(0))
        'Next
    End Sub


    Private Sub LoadMetasynchronous()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("spGetMetasyn", SqlConnection1)
        sqlCmd.Parameters.Add("@Pt_ID1", SqlDbType.Int)
        sqlCmd.Parameters.Add("@Event_Id", SqlDbType.Char)
        sqlCmd.Parameters("@Pt_ID1").Value = GV_CUR_PATID
        sqlCmd.Parameters("@Event_Id").Value = GV_SELECTED_EVENTID
        sqlCmd.CommandType = CommandType.StoredProcedure
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("brst_screen", GetType(String)))
            list.Columns.Add(New DataColumn("Event_ID", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("brst_screen")), "", objReader("brst_screen"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Event_ID")), "", objReader("Event_ID"))
                i = i + 1
            Loop
            Me.CboxMetasEvent.DataSource = list
            Me.CboxMetasEvent.DisplayMember = "brst_screen"
            Me.CboxMetasEvent.ValueMember = "Event_ID"

        Catch e As Exception
            'MsgBox(e.Source & e.Message)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadDoctor()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  83", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxDoctor.DataSource = list
            Me.cbxDoctor.DisplayMember = "code_desc"
            Me.cbxDoctor.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadCaseType()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 84", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxCaseType.DataSource = list
            Me.cbxCaseType.DisplayMember = "code_desc"
            Me.cbxCaseType.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadLaterality()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 9", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxLaterality.DataSource = list
            Me.cbxLaterality.DisplayMember = "code_desc"
            Me.cbxLaterality.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub


    Private Sub displayPatientData(ByVal currentEventID As String)
        'currentDS.Tables("dtInvestigation").Rows(0).Item(
        'Load from investigation table
        'currentEventID = "E023"
        Dim patientName As String
        Dim patientNRIC As String
        Dim patientAge As String
        Dim inc As Integer

        Dim count As Integer

        'if currenteventID is empty, disableallfields and exit sub
        If (currentEventID = "") Then
            Exit Sub
        Else
        End If

        'Load from event table
        Dim CNnWind As New SqlClient.SqlConnection(GV_CONNETION)
        'Dim datetimepickertext As String = DateTimePicker1.Text.ToString()

        'Dim currentDOBtext As String = DOB.Text.ToString
        'Dim DAEvent As New SqlClient.SqlDataAdapter("select * from Event where convert(varchar, date_tb,103) = '" & currentDOBtext & "' and status <> 'D'", CNnWind) '& FormatDateTime(DateTimePicker1.Text, DateFormat.ShortDate) & "'", CNnWind) 'where date_tb = '" & datetimepickertext & "'", CNnWind)
        Dim DAEvent As New SqlClient.SqlDataAdapter("select * from Event where Event_ID = '" & currentEventID & "' and status <> 'D'", CNnWind) '& FormatDateTime(DateTimePicker1.Text, DateFormat.ShortDate) & "'", CNnWind) 'where date_tb = '" & datetimepickertext & "'", CNnWind)

        Dim currentPt_id As String

        'Load from event table
        Try
            DSNEvent = New DataSet()
            CNnWind.Open()
            DAEvent.Fill(DSNEvent, "dtEvent")
            CNnWind.Close()

            'reset event counter if there are records
            If DSNEvent.Tables("dtEvent").Rows.Count >= 1 Then
                inc = 0
            End If

            'load from event table
            currentEventID = DSNEvent.Tables("dtEvent").Rows(inc).Item("Event_ID")
            currentPt_id = DSNEvent.Tables("dtEvent").Rows(inc).Item("Pt_id1")

            'lblEvent.Text = currentEventID
            GV_SELECTED_EVENTID = currentEventID
            DOB.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("date_tb")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("date_tb"))
            DateTimePicker1.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("date_cn")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("date_cn"))
            cbxDoctor.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("doc_inc")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("doc_inc"))
            cbxCaseType.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("case_type")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("case_type"))
            cbxLaterality.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("brst_screen")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("brst_screen"))
            CboxMeta.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("Metasyn_Status")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("Metasyn_Status"))
            GV_CUR_PATID = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("Pt_id1")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("Pt_id1"))


            If (currentselectedtab = "TabPage: {Event}") Then

                Lbl_EnBy.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("EnteredBy")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("EnteredBy"))
                lbl_entereddatetime.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("EnteredTime")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("EnteredTime"))
                Lbl_UpdBy.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("UpdatedBy")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("UpdatedBy"))
                lbl_updateddatetime.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("UpdatedTime")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("UpdatedTime"))
                Lbl_LockBy.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("LockedBy")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("LockedBy"))
                lbl_LockedDateTime.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("LockedTime")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("LockedTime"))

            End If

            Lbl_EnBy.Visible = True
            Lbl_UpdBy.Visible = True
            Lbl_LockBy.Visible = True
            lbl_entereddatetime.Visible = True
            lbl_updateddatetime.Visible = True
            lbl_LockedDateTime.Visible = True



        Catch a As Exception
            'turned off by cherwei, used for validation
            'disableAllFields()
            'enableAllFields()
            'MsgBox(a.ToString)
            Exit Sub
        End Try

        Dim currenteventstatus As String
        currenteventstatus = DSNEvent.Tables("dtEvent").Rows(inc).Item("Status")
        If currenteventstatus = "P" Then
            DOB.Enabled = False
            DateTimePicker1.Enabled = False
            cbxDoctor.Enabled = False
            cbxCaseType.Enabled = False
            cbxLaterality.Enabled = False
            CboxMeta.Enabled = False
            CboxMetasEvent.Enabled = False
            'btnSave.Enabled = False
        Else
            DOB.Enabled = True
            DateTimePicker1.Enabled = True
            cbxDoctor.Enabled = True
            cbxCaseType.Enabled = True
            cbxLaterality.Enabled = True
            CboxMeta.Enabled = True
            CboxMetasEvent.Enabled = True
            'btnSave.Enabled = True
        End If

        LoadMetasynchronous()
        CboxMetasEvent.SelectedValue = DSNEvent.Tables("dtEvent").Rows(inc).Item("Metasynchronous")

        'Load from patient table, retrieve name and nric
        Dim DAPatient As New SqlClient.SqlDataAdapter("select distinct * from patients where Pt_id1 = '" & currentPt_id & "'", CNnWind)
        DSNPatient = New DataSet()
        CNnWind.Open()
        DAPatient.Fill(DSNPatient, "dtPatient")
        CNnWind.Close()

        count = DSNPatient.Tables("dtPatient").Rows.Count
        If (count > 0) Then
            'PatName.Text = DSNPatient.Tables("dtPatient").Rows(0).Item("PtName")
            'PatNRIC.Text = DSNPatient.Tables("dtPatient").Rows(0).Item("PtNRIC")
            'lblAge.Text = DSNPatient.Tables("dtPatient").Rows(0).Item("PtAge")
        End If

        'Load from investigation table
        Dim DAInvestigation As New SqlClient.SqlDataAdapter("select * from Investigation where event_id = '" & currentEventID & "' and status <> 'D'", CNnWind)
        DSNInvestigation = New DataSet()
        CNnWind.Open()
        DAInvestigation.Fill(DSNInvestigation, "dtInvestigation")
        CNnWind.Close()

        Try
            count = DSNInvestigation.Tables("dtInvestigation").Rows.Count
        Catch ex As Exception
            cbxCXR.Enabled = False
            cbxCT.Enabled = False
            cbxBone.Enabled = False
            RichTextNotes.Enabled = False
            GV_SELECTED_INVESTID = ""
        End Try
        If (count > 0) Then
            GV_SELECTED_INVESTID = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("Inv_id")
            cbxCXR.SelectedValue = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("CXR")
            cbxCT.Text = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("CT")
            cbxBone.Text = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("BoneScan")
            RichTextNotes.Text = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("Notes")
            cbxCXR.Enabled = True
            cbxCT.Enabled = True
            cbxBone.Enabled = True
            RichTextNotes.Enabled = True

            If (currentselectedtab = "TabPage: {Investigation}") Then

                Lbl_EnBy.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("EnteredBy")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("EnteredBy"))
                lbl_entereddatetime.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("EnteredTime")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("EnteredTime"))
                Lbl_UpdBy.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("UpdatedBy")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("UpdatedBy"))
                lbl_updateddatetime.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("UpdatedTime")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("UpdatedTime"))
                Lbl_LockBy.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("LockedBy")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("LockedBy"))
                lbl_LockedDateTime.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("LockedTime")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("LockedTime"))
            End If

        Else
            cbxCXR.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("CXR")
            cbxCT.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("CT")
            cbxBone.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("BoneScan")
            RichTextNotes.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("Notes")
            cbxCXR.Enabled = False
            cbxCT.Enabled = False
            cbxBone.Enabled = False
            RichTextNotes.Enabled = False

        End If

        If currenteventstatus = "P" Then 'P:lock so disable all fields
            cbxCXR.Enabled = False
            cbxCT.Enabled = False
            cbxBone.Enabled = False
            RichTextNotes.Enabled = False

            'Disable all buttons
            btnApprove.Enabled = False
            btnHisology2.Enabled = False
            btnHistologySave.Enabled = False
            btnEventSave.Enabled = False
            btnInvest2.Enabled = False
            btnInvSave.Enabled = False
            btnMedHis2.Enabled = False
            btnHistorySave.Enabled = False
            btnTxRec2.Enabled = False
            btnTxRecSave.Enabled = False
        ElseIf (count = 0) Then
            cbxCXR.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("CXR")
            cbxCT.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("CT")
            cbxBone.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("BoneScan")
            RichTextNotes.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("Notes")
            cbxCXR.Enabled = False
            cbxCT.Enabled = False
            cbxBone.Enabled = False
            RichTextNotes.Enabled = False
        Else
            cbxCXR.Enabled = True
            cbxCT.Enabled = True
            cbxBone.Enabled = True
            RichTextNotes.Enabled = True

            'Enable all buttons
            btnApprove.Enabled = True
            btnHisology2.Enabled = True
            btnHistologySave.Enabled = True
            btnEventSave.Enabled = True
            btnInvest2.Enabled = True
            btnInvSave.Enabled = True
            btnMedHis2.Enabled = True
            btnHistorySave.Enabled = True
            btnTxRec2.Enabled = True
            btnTxRecSave.Enabled = True

        End If


        'Load from history table
        Dim DAHistory As New SqlClient.SqlDataAdapter("select * from History where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)
        DSNHistory = New DataSet()
        CNnWind.Open()
        DAHistory.Fill(DSNHistory, "dtHistory")
        CNnWind.Close()
        count = DSNHistory.Tables("dtHistory").Rows.Count
        If (count > 0) Then
            GV_SELECTED_HISTORYID = DSNHistory.Tables("dtHistory").Rows(0).Item("History_ID")
            cbxHistory.Text = DSNHistory.Tables("dtHistory").Rows(0).Item("FamilyHistory")
            cbxStatus.Text = DSNHistory.Tables("dtHistory").Rows(0).Item("Menstrual")
            cbxHistory.Enabled = True
            cbxStatus.Enabled = True


            If (currentselectedtab = "TabPage: {History}") Then
                Lbl_EnBy.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("EnteredBy")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("EnteredBy"))
                lbl_entereddatetime.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("EnteredTime")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("EnteredTime"))
                Lbl_UpdBy.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("UpdatedBy")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("UpdatedBy"))
                lbl_updateddatetime.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("UpdatedTime")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("UpdatedTime"))
                Lbl_LockBy.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("LockedBy")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("LockedBy"))
                lbl_LockedDateTime.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("LockedTime")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("LockedTime"))
            End If

        Else
            cbxHistory.Text = "" 'DSNHistory.Tables("dtHistory").Rows(inc).Item("FamilyHistory")
            cbxStatus.Text = "" ' DSNHistory.Tables("dtHistory").Rows(inc).Item("Menstrual")

            cbxHistory.Enabled = False
            cbxStatus.Enabled = False
            GV_SELECTED_HISTORYID = ""
        End If


        If currenteventstatus = "P" Then
            cbxHistory.Enabled = False
            cbxStatus.Enabled = False
        ElseIf (count = 0) Then
            cbxHistory.Text = "" 'DSNHistory.Tables("dtHistory").Rows(inc).Item("FamilyHistory")
            cbxStatus.Text = "" ' DSNHistory.Tables("dtHistory").Rows(inc).Item("Menstrual")

            cbxHistory.Enabled = False
            cbxStatus.Enabled = False
            GV_SELECTED_HISTORYID = ""
        Else

            cbxHistory.Enabled = True
            cbxStatus.Enabled = True
        End If

        'Load from histology table

        Dim DAHistology As New SqlClient.SqlDataAdapter("select * from Histology where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)
        DSNHistology = New DataSet()
        CNnWind.Open()
        DAHistology.Fill(DSNHistology, "dtHistology")
        CNnWind.Close()

        count = DSNHistology.Tables("dtHistology").Rows.Count
        If (count > 0) Then
            GV_SELECTED_HISTOLOGYID = DSNHistology.Tables("dtHistology").Rows(0).Item("histo_id")
            txtTumourSize.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size"))
            cbxExtChestWall.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw"))
            cbxClinAxillaryLN.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln"))
            cbxTypeBiopsy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type"))
            dtDateBiopsy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy"))
            cbxHistoDx.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx"))
            DtPrisurg.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg"))
            cbxTypeSurg.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type"))
            cbxReconstruction.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction"))
            cboxNeoadjuvant.Checked = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj"))
            cboxLocalRec.Checked = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local"))
            cboxSystemic.Checked = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic"))
            txtPhysicalNotes.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes"))
            txtHistoNotes.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes"))
            txtHisto_TumourSize.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size"))
            cbxHistoType.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type"))
            cbxHistoGrade.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade"))
            cbxDCIS.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis"))
            cbxLymhovascular.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv"))
            cbxMargin_invasive.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca"))
            cboxMarginDCIS.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis"))
            cbxradialMargin.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg"))
            txtRadialMargin.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size"))
            txtDeepMargin.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size"))
            cbxSentinel_LN.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1"))
            cbxSentinelLNPolarity.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_2")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_2"))
            txtTotal_Ax_LN_Postive.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos"))
            txtTotal_Ax_LN_Found.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

            cbxSide.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("side")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("side"))

            'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
            cbxER_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("er_status"))
            cbxPR_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status"))
            cbxErbB2.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status"))
            cbxcT_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6"))
            cbxN_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6"))
            cbxM_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6"))


            If (currentselectedtab = "TabPage: {Histology}") Then
                Lbl_EnBy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("EnteredBy")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("EnteredBy"))
                lbl_entereddatetime.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("EnteredTime")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("EnteredTime"))
                Lbl_UpdBy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("UpdatedBy")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("UpdatedBy"))
                lbl_updateddatetime.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("UpdatedTime")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("UpdatedTime"))
                Lbl_LockBy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("LockedBy")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("LockedBy"))
                lbl_LockedDateTime.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("LockedTime")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("LockedTime"))

            End If

            txtTumourSize.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
            cbxExtChestWall.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
            cbxClinAxillaryLN.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
            cbxTypeBiopsy.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
            dtDateBiopsy.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
            cbxHistoDx.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
            DtPrisurg.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
            cbxTypeSurg.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
            cbxReconstruction.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
            cboxNeoadjuvant.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
            cboxLocalRec.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
            cboxSystemic.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
            txtPhysicalNotes.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
            txtHistoNotes.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
            txtHisto_TumourSize.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
            cbxHistoType.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
            cbxHistoGrade.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
            cbxDCIS.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
            cbxLymhovascular.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
            cbxMargin_invasive.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
            cboxMarginDCIS.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
            cbxradialMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
            txtRadialMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
            txtDeepMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
            cbxSentinel_LN.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
            cbxSentinelLNPolarity.Enabled = True
            txtTotal_Ax_LN_Postive.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
            txtTotal_Ax_LN_Found.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

            'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
            cbxER_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
            cbxPR_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
            cbxErbB2.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
            cbxcT_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
            cbxN_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
            cbxM_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")

            cbxSide.Enabled = True

        Else
            txtTumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_tum_size")
            cbxExtChestWall.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("Ext_cw")
            cbxClinAxillaryLN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_ax_ln")
            cbxTypeBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("biopsy_Type")
            dtDateBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_biopsy")
            cbxHistoDx.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_Dx")
            DtPrisurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_pri_surg")
            cbxTypeSurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("surg_type")
            cbxReconstruction.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("reconstruction")
            cboxNeoadjuvant.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Neoadj")
            cboxLocalRec.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Local")
            cboxSystemic.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Systemic")
            txtPhysicalNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("add_physurg_notes")
            txtHistoNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("other_histo_notes")
            txtHisto_TumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_tum_size")
            cbxHistoType.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_type")
            cbxHistoGrade.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_grade")
            cbxDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ass_dcis")
            cbxLymhovascular.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("lymphovas_inv")
            cbxMargin_invasive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_inv_ca")
            cboxMarginDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_dcis")
            cbxradialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg")
            txtRadialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg_size")
            txtDeepMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("deep_marg_size")
            cbxSentinel_LN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("SLN_1")
            'cbxSentinelLNPolarity.Text = ""
            txtTotal_Ax_LN_Postive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_pos")
            txtTotal_Ax_LN_Found.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))
            cbxER_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("er_status")
            cbxPR_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("pr_status")
            cbxErbB2.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("c_erbb2_status")
            cbxcT_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("t_stage_6")
            cbxN_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("n_stage_6")
            cbxM_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("m_stage_6")

            cbxSide.Text = ""

            txtTumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
            cbxExtChestWall.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
            cbxClinAxillaryLN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
            cbxTypeBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
            dtDateBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
            cbxHistoDx.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
            DtPrisurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
            cbxTypeSurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
            cbxReconstruction.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
            cboxNeoadjuvant.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
            cboxLocalRec.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
            cboxSystemic.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
            txtPhysicalNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
            txtHistoNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
            txtHisto_TumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
            cbxHistoType.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
            cbxHistoGrade.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
            cbxDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
            cbxLymhovascular.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
            cbxMargin_invasive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
            cboxMarginDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
            cbxradialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
            txtRadialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
            txtDeepMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
            cbxSentinel_LN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
            cbxSentinelLNPolarity.Enabled = False
            txtTotal_Ax_LN_Postive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
            txtTotal_Ax_LN_Found.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

            'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
            cbxER_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
            cbxPR_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
            cbxErbB2.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
            cbxcT_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
            cbxN_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
            cbxM_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")

            cbxSide.Enabled = False

            GV_SELECTED_HISTOLOGYID = ""
        End If

        If currenteventstatus = "P" Then 'P:lock so disable all fields
            cboxNeoadjuvant.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Neoadj")
            cboxLocalRec.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Local")
            cboxSystemic.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Systemic")
            txtTumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
            cbxExtChestWall.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
            cbxClinAxillaryLN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
            cbxTypeBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
            dtDateBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
            cbxHistoDx.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
            DtPrisurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
            cbxTypeSurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
            cbxReconstruction.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
            cboxNeoadjuvant.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
            cboxLocalRec.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
            cboxSystemic.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
            txtPhysicalNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
            txtHistoNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
            txtHisto_TumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
            cbxHistoType.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
            cbxHistoGrade.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
            cbxDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
            cbxLymhovascular.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
            cbxMargin_invasive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
            cboxMarginDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
            cbxradialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
            txtRadialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
            txtDeepMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
            cbxSentinel_LN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
            cbxSentinelLNPolarity.Enabled = False
            txtTotal_Ax_LN_Postive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
            txtTotal_Ax_LN_Found.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

            'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
            cbxER_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
            cbxPR_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
            cbxErbB2.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
            cbxcT_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
            cbxN_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
            cbxM_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")

            cbxSide.Enabled = False

        ElseIf (count = 0) Then
            txtTumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_tum_size")
            cbxExtChestWall.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("Ext_cw")
            cbxClinAxillaryLN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_ax_ln")
            cbxTypeBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("biopsy_Type")
            dtDateBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_biopsy")
            cbxHistoDx.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_Dx")
            DtPrisurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_pri_surg")
            cbxTypeSurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("surg_type")
            cbxReconstruction.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("reconstruction")
            txtPhysicalNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("add_physurg_notes")
            txtHistoNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("other_histo_notes")
            txtHisto_TumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_tum_size")
            cbxHistoType.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_type")
            cbxHistoGrade.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_grade")
            cbxDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ass_dcis")
            cbxLymhovascular.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("lymphovas_inv")
            cbxMargin_invasive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_inv_ca")
            cboxMarginDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_dcis")
            cbxradialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg")
            txtRadialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg_size")
            txtDeepMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("deep_marg_size")
            cbxSentinel_LN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("SLN_1")
            cbxSentinelLNPolarity.Text = ""
            dtDateBiopsy.Text = ""
            DtPrisurg.Text = ""
            txtTotal_Ax_LN_Postive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_pos")
            txtTotal_Ax_LN_Found.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))
            cbxER_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("er_status")
            cbxPR_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("pr_status")
            cbxErbB2.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("c_erbb2_status")
            cbxcT_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("t_stage_6")
            cbxN_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("n_stage_6")
            cbxM_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("m_stage_6")

            cbxSide.Text = ""

            txtTumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
            cbxExtChestWall.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
            cbxClinAxillaryLN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
            cbxTypeBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
            dtDateBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
            cbxHistoDx.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
            DtPrisurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
            cbxTypeSurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
            cbxReconstruction.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
            cboxNeoadjuvant.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
            cboxLocalRec.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
            cboxSystemic.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
            txtPhysicalNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
            txtHistoNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
            txtHisto_TumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
            cbxHistoType.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
            cbxHistoGrade.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
            cbxDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
            cbxLymhovascular.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
            cbxMargin_invasive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
            cboxMarginDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
            cbxradialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
            txtRadialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
            txtDeepMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
            cbxSentinel_LN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
            cbxSentinelLNPolarity.Enabled = False
            txtTotal_Ax_LN_Postive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
            txtTotal_Ax_LN_Found.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

            'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
            cbxER_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
            cbxPR_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
            cbxErbB2.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
            cbxcT_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
            cbxN_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
            cbxM_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")

            cbxSide.Enabled = False

            GV_SELECTED_HISTOLOGYID = ""
        Else
            cboxNeoadjuvant.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Neoadj")
            cboxLocalRec.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Local")
            cboxSystemic.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Systemic")
            txtTumourSize.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
            cbxExtChestWall.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
            cbxClinAxillaryLN.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
            cbxTypeBiopsy.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
            dtDateBiopsy.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
            cbxHistoDx.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
            DtPrisurg.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
            cbxTypeSurg.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
            cbxReconstruction.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
            cboxNeoadjuvant.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
            cboxLocalRec.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
            cboxSystemic.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
            txtPhysicalNotes.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
            txtHistoNotes.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
            txtHisto_TumourSize.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
            cbxHistoType.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
            cbxHistoGrade.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
            cbxDCIS.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
            cbxLymhovascular.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
            cbxMargin_invasive.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
            cboxMarginDCIS.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
            cbxradialMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
            txtRadialMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
            txtDeepMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
            cbxSentinel_LN.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
            cbxSentinelLNPolarity.Enabled = True
            txtTotal_Ax_LN_Postive.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
            txtTotal_Ax_LN_Found.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

            'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
            cbxER_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
            cbxPR_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
            cbxErbB2.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
            cbxcT_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
            cbxN_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
            cbxM_Status.Enabled = True

            cbxSide.Enabled = True
        End If

        'Load from TxRecommendation
        Dim DATxRecommendation As New SqlClient.SqlDataAdapter("select * from recom where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)
        DSNTxRecommendation = New DataSet()
        CNnWind.Open()
        DATxRecommendation.Fill(DSNTxRecommendation, "dtTxRecommendation")
        CNnWind.Close()

        count = DSNTxRecommendation.Tables("dtTxRecommendation").Rows.Count
        If (count > 0) Then
            GV_SELECTED_TXID = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recom_id")
            cbxBTBRecommend.Text = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommendation")
            cboxChemo.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
            cboxHormonal.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
            cboxRadio.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
            cboxSurgery.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
            cboxTargerted.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
            cboxComplete.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
            txtComments.Text = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
            txtNotes.Text = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("update_notes")

            If (currentselectedtab = "TabPage: {TxRecommendation}") Then
                Lbl_EnBy.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("EnteredBy")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("EnteredBy"))
                lbl_entereddatetime.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("EnteredTime")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("EnteredTime"))
                Lbl_UpdBy.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("UpdatedBy")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("UpdatedBy"))
                lbl_updateddatetime.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("UpdatedTime")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("UpdatedTime"))
                Lbl_LockBy.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("LockedBy")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("LockedBy"))
                lbl_LockedDateTime.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("LockedTime")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("LockedTime"))
            End If

            cbxBTBRecommend.Enabled = True
            cboxChemo.Enabled = True  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
            cboxHormonal.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
            cboxRadio.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
            cboxSurgery.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
            cboxTargerted.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
            cboxComplete.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
            txtComments.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
            txtNotes.Enabled = True
        Else
            cbxBTBRecommend.Text = ""
            cboxChemo.Checked = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
            cboxHormonal.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
            cboxRadio.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
            cboxSurgery.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
            cboxTargerted.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
            cboxComplete.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
            txtComments.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
            txtNotes.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("update_notes")

            cbxBTBRecommend.Enabled = False
            cboxChemo.Enabled = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
            cboxHormonal.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
            cboxRadio.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
            cboxSurgery.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
            cboxTargerted.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
            cboxComplete.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
            txtComments.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
            txtNotes.Enabled = False

            GV_SELECTED_TXID = ""
        End If

        If currenteventstatus = "P" Then
            cbxBTBRecommend.Enabled = False
            cboxChemo.Enabled = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
            cboxHormonal.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
            cboxRadio.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
            cboxSurgery.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
            cboxTargerted.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
            cboxComplete.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
            txtComments.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
            txtNotes.Enabled = False
        ElseIf (count = 0) Then
            cbxBTBRecommend.Text = ""
            cboxChemo.Checked = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
            cboxHormonal.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
            cboxRadio.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
            cboxSurgery.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
            cboxTargerted.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
            cboxComplete.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
            txtComments.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
            txtNotes.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("update_notes")

            cbxBTBRecommend.Enabled = False
            cboxChemo.Enabled = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
            cboxHormonal.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
            cboxRadio.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
            cboxSurgery.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
            cboxTargerted.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
            cboxComplete.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
            txtComments.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
            txtNotes.Enabled = False

            GV_SELECTED_TXID = ""
        Else
            cbxBTBRecommend.Enabled = True
            cboxChemo.Enabled = True  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
            cboxHormonal.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
            cboxRadio.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
            cboxSurgery.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
            cboxTargerted.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
            cboxComplete.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
            txtComments.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
            txtNotes.Enabled = True
        End If




        'Load from RECURRENCE table
        Me.recurrenceDataAdapter = New SqlClient.SqlDataAdapter("select [recurrence_date],[recurrence_site],[dxMethod],[treatment],[remarks],[status] from recurrence where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)


        CNnWind.Open()
        'Create two DataTables.

        'Create columns, and add them to the table.
        Dim cRecurDate As New DataColumn("recurrence_date")
        Dim cRecurSite As New DataColumn("recurrence_site")
        Dim cDxMethod As New DataColumn("dxMethod")
        Dim cTreatment As New DataColumn("treatment")
        Dim cRemarkds As New DataColumn("remarks")

        Me.recurrenceBindingSource1.Columns.Clear()


        Me.recurrenceBindingSource1.Columns.Add(cRecurDate)
        Me.recurrenceBindingSource1.Columns.Add(cRecurSite)
        Me.recurrenceBindingSource1.Columns.Add(cDxMethod)
        Me.recurrenceBindingSource1.Columns.Add(cTreatment)
        Me.recurrenceBindingSource1.Columns.Add(cRemarkds)

        Me.recurrenceBindingSource1.Rows.Clear()
        Me.recurrenceDataAdapter.Fill(Me.recurrenceBindingSource1)
        CNnWind.Close()
        recurrenceGrid.DataSource = Me.recurrenceBindingSource1.DefaultView





        'maxrows = DSNEvent.Tables("dtEvent").Rows.Count
        'inc = 0

        'GV_CUR_PATNRIC = PatNRIC.Text
        'GV_CUR_PATNAME = PatName.Text

        'Catch
        'MsgBox("No records found for selected BTB date: '" & DOB.Text & "'")
        'End Try

    End Sub


    Private Sub GetChildren(ByVal parentNode As TreeNode) 'As List(Of String)
        'Dim nodes As List(Of String)
        'GetAllChildren(parentNode, nodes)
        'Return nodes
    End Sub

    Private Sub CheckNodesForTree(ByVal nodes As TreeNodeCollection)
        'For each (ByVal TreeNodes in nodes)

        'End

        For Each node_1 As TreeNode In nodes
            Dim selectedNodename1 As String = node_1.Text
        Next



    End Sub



    Private Sub DisplayChildNodesText(ByVal Node As TreeNode)
        Dim i As Integer

        ' Display the node's text value.
        'Message.Text &= node.Text & "<br />"

        'For i = 0 To Node.Chile

        ' Recursively call the DisplayChildNodeText method to
        ' traverse the tree and display all the child nodes.

        'DisplayChildNodeText(node.ChildNodes(i))

        'Next i


    End Sub
    Private Sub btnMedHis_Click2(ByVal sender As System.Object, ByVal e As System.EventArgs)

        GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        'If Trim(GV_SELECTED_EVENTID) = "" Then
        'MsgBox("Please select event.")
        'Exit Sub
        'End If
        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event. There is alreadly an existing medical history for current event.")
            Exit Sub
        End If

        Dim selectedparenteventid As String
        Dim somename2 As String
        Dim totalcount As String


        selectedparenteventid = TreeView2.SelectedNode.Name
        somename2 = TreeView2.SelectedNode.Nodes.Count

        'check to see if the current selected row is Parent row 'E'
        'If (selectedparenteventid.Trim.Substring(0, 1) = "E") Then
        'does not need further check as selected row is alreadly the parent node
        'Else
        'selectedparenteventid = TreeView2.SelectedNode.Parent.Name
        'End If




        'Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        'Dim DAHistoryTemp As New SqlClient.SqlDataAdapter("SELECT HISTORY_MSG, EVENT_ID, PT_Id1, HISTORY_ID, Status FROM HISTORY where STATUS = 'A' and EVENT_ID = '" & selectedparenteventid & "'", CNnwind2)
        'Dim DSNWindTemp As DataSet
        'DSNWindTemp = New DataSet()
        'DAHistoryTemp.Fill(DSNWindTemp, "dtHistoryTemp")
        'totalcount = DSNWindTemp.Tables(0).Rows.Count

        'If (totalcount > 0) Then
        'MsgBox("Please add new event. There is alreadly an existing medical history for current event.")
        'Exit Sub
        'End If


        'If TreeView2.SelectedNode Is Nothing Then
        'MsgBox("Please select event.")
        'Exit Sub
        'Else

        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_HISTORYID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "H" Then GV_SELECTED_HISTORYID = TreeView2.SelectedNode.Name Else GV_SELECTED_HISTORYID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If

        'End If

        FrmHistory.Close()
        FrmHistory.Show()
        FrmHistory.Focus()
    End Sub



    Private Sub btnMedHis_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMedHis.Click
        'Added by cherwei to check for lock status and disallow adding new data if locked
        Dim vEventIDtemp As String
        vEventIDtemp = ""

        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event")
            Exit Sub
        End If

        vEventIDtemp = TreeView2.SelectedNode.Name
        If vEventIDtemp.StartsWith("E") Then
        Else
            vEventIDtemp = TreeView2.SelectedNode.Parent.Name
        End If

        If IsApprovedEvent(vEventIDtemp) = True Then
            MsgBox("Please unlock event before adding new medical history for Event: " + vEventIDtemp)
            Exit Sub
        End If

        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        If Trim(GV_SELECTED_EVENTID) = "" Then
            MsgBox("Please select event.")
            Exit Sub
        End If

        Dim selectedparenteventid As String
        Dim somename2 As String
        Dim totalcount As String


        selectedparenteventid = TreeView2.SelectedNode.Name
        somename2 = TreeView2.SelectedNode.Nodes.Count

        'check to see if the current selected row is Parent row 'E'
        If (selectedparenteventid.Trim.Substring(0, 1) = "E") Then
            'does not need further check as selected row is alreadly the parent node
        Else
            selectedparenteventid = TreeView2.SelectedNode.Parent.Name
        End If


        'updated by cherwei on 14 May 2009 to include records with 'A' and 'P' status 

        Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAHistoryTemp As New SqlClient.SqlDataAdapter("SELECT HISTORY_MSG, EVENT_ID, PT_Id1, HISTORY_ID, Status FROM HISTORY where STATUS <> 'D' and EVENT_ID = '" & selectedparenteventid & "'", CNnwind2)
        Dim DSNWindTemp As DataSet
        DSNWindTemp = New DataSet()
        DAHistoryTemp.Fill(DSNWindTemp, "dtHistoryTemp")
        totalcount = DSNWindTemp.Tables(0).Rows.Count

        If (totalcount > 0) Then
            MsgBox("Please add new event. There is alreadly an existing medical history for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")
            Exit Sub
        End If



        'If TreeView2.SelectedNode Is Nothing Then
        'MsgBox("Please select event.")
        'Exit Sub
        'Else

        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_HISTORYID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "H" Then GV_SELECTED_HISTORYID = TreeView2.SelectedNode.Name Else GV_SELECTED_HISTORYID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If

        'End If

        FrmHistory.Close()
        FrmHistory.Show()
        FrmHistory.Focus()


    End Sub


    Private Sub btnInvest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInvest.Click
        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        'Added by cherwei to check for lock status and disallow adding new data if locked
        Dim vEventIDtemp As String
        vEventIDtemp = ""
        vEventIDtemp = TreeView2.SelectedNode.Name
        If vEventIDtemp.StartsWith("E") Then
        Else
            vEventIDtemp = TreeView2.SelectedNode.Parent.Name
        End If

        If IsApprovedEvent(vEventIDtemp) = True Then
            MsgBox("Please unlock event before adding new investigation for Event: " + vEventIDtemp)
            Exit Sub
        End If

        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        If Trim(GV_SELECTED_EVENTID) = "" Then
            MsgBox("Please select event.")
            Exit Sub
        End If

        If TreeView2.SelectedNode Is Nothing Then
            MsgBox("Please select event.")
            Exit Sub
        Else
        End If
        'Dim oFrmInvestigation As New FrmInvestigation()
        'oFrmInvestigation.Show()
        Dim selectedparenteventid As String
        Dim somename2 As String
        Dim totalcount As String


        selectedparenteventid = TreeView2.SelectedNode.Name
        somename2 = TreeView2.SelectedNode.Nodes.Count

        'check to see if the current selected row is Parent row 'E'
        If (selectedparenteventid.Trim.Substring(0, 1) = "E") Then
            'does not need further check as selected row is alreadly the parent node
        Else
            selectedparenteventid = TreeView2.SelectedNode.Parent.Name
        End If

        Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAInvestigationTemp As New SqlClient.SqlDataAdapter("SELECT INV_MSG, EVENT_ID, PT_Id1, INV_ID, Status FROM INVESTIGATION where STATUS <> 'D' and EVENT_ID = '" & selectedparenteventid & "'", CNnwind2)
        Dim DSNWindTemp As DataSet
        DSNWindTemp = New DataSet()
        DAInvestigationTemp.Fill(DSNWindTemp, "dtInvestigationTemp")
        totalcount = DSNWindTemp.Tables(0).Rows.Count

        If (totalcount > 0) Then
            MsgBox("Please add new event. There is alreadly an existing investigation for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")
            Exit Sub
        End If

        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_INVESTID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "I" Then GV_SELECTED_INVESTID = TreeView2.SelectedNode.Name Else GV_SELECTED_INVESTID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If

        FrmInvestigation.Close()
        FrmInvestigation.Show()
        FrmInvestigation.Focus()
    End Sub
    Private Sub btnInvest_Click2(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If


        If TreeView2.SelectedNode Is Nothing Then
            MsgBox("Please select event.")
            Exit Sub
        Else

            If TreeView2.SelectedNode.Level = 0 Then
                GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
                GV_SELECTED_INVESTID = ""
            End If

            If TreeView2.SelectedNode.Level = 1 Then
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "I" Then GV_SELECTED_INVESTID = TreeView2.SelectedNode.Name Else GV_SELECTED_INVESTID = ""
                GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
            End If

        End If
        'Dim oFrmInvestigation As New FrmInvestigation()
        'oFrmInvestigation.Show()
        FrmInvestigation.Close()
        FrmInvestigation.Show()
        FrmInvestigation.Focus()

    End Sub

    Private Sub btnHisology_Click2(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        If TreeView2.SelectedNode Is Nothing Then
            MsgBox("Please select event.")
            Exit Sub
        Else

        End If



        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_HISTOLOGYID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "S" Then GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name Else GV_SELECTED_HISTOLOGYID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If


        FrmHistology.Close()
        FrmHistology.Show()
        FrmHistology.Focus()

    End Sub
    Private Sub btnHisology_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHisology.Click
        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        'Added by cherwei to check for lock status and disallow adding new data if locked
        Dim vEventIDtemp As String
        vEventIDtemp = ""

        vEventIDtemp = TreeView2.SelectedNode.Name
        If vEventIDtemp.StartsWith("E") Then
        Else
            vEventIDtemp = TreeView2.SelectedNode.Parent.Name
        End If

        'If IsApprovedEvent(vEventIDtemp) = True Then
        'MsgBox("Please unlock event before adding new Histology for Event: " + vEventIDtemp)
        'Exit Sub
        'End If

        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        If Trim(GV_SELECTED_EVENTID) = "" Then
            MsgBox("Please select event.")
            Exit Sub
        End If

        If TreeView2.SelectedNode Is Nothing Then
            MsgBox("Please select event.")
            Exit Sub
        Else

        End If

        Dim selectedparenteventid As String
        Dim somename2 As String
        Dim totalcount As String

        selectedparenteventid = TreeView2.SelectedNode.Name
        somename2 = TreeView2.SelectedNode.Nodes.Count

        'check to see if curreny selected row is parent row 'E'
        If (selectedparenteventid.Trim.Substring(0, 1) = "E") Then

        Else
            selectedparenteventid = TreeView2.SelectedNode.Parent.Name
        End If

        Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAHistologyTemp As New SqlClient.SqlDataAdapter("SELECT Histology_msg, EVENT_ID, PT_Id1, Histo_ID , Status FROM Histology where STATUS <> 'D' and EVENT_ID = '" & selectedparenteventid & "'", CNnwind2)
        Dim DSNWindTemp As DataSet
        DSNWindTemp = New DataSet()
        DAHistologyTemp.Fill(DSNWindTemp, "dtHistologyTemp")
        totalcount = DSNWindTemp.Tables(0).Rows.Count

        If (totalcount > 0) Then
            MsgBox("Please add new event. There is alreadly an existing histology for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")

            Exit Sub
        End If

        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_HISTOLOGYID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            '   GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "S" Then GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name Else GV_SELECTED_HISTOLOGYID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If

        'End If
        'Dim oFrmHistology As New FrmHistology()
        'oFrmHistology.Show()
        FrmHistology.Close()
        FrmHistology.Show()
        FrmHistology.Focus()

    End Sub

    Private Sub FrmDiagnosis_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus

    End Sub

    Private Sub FrmDiagnosis_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave

    End Sub

    Private Sub FrmDiagnosis_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.Text = "Login User: " & GV_USERNAME & "    /  Data Entry - " & GV_CUR_PATNRIC & ", " & GV_CUR_PATNAME
        InitialTreeViewMsg()
        ListPatientDiagnosis()

        DeleteToolStripMenuItem.Enabled = GV_FRMEVENT_ALLOW_EDIT
        ApproveToolStripMenuItem.Enabled = GV_FRMEVENT_ALLOW_APPROVE
        UnapproveToolStripMenuItem.Enabled = GV_FRMEVENT_ALLOW_APPROVE
        MoveToEventToolStripMenuItem.Enabled = GV_FRMEVENT_ALLOW_EDIT
        CopyToEventToolStripMenuItem.Enabled = GV_FRMEVENT_ALLOW_EDIT
        SortEventByAscdecToolStripMenuItem.Enabled = GV_FRMEVENT_ALLOW_EDIT

        btnApprove.Enabled = GV_FRMEVENT_ALLOW_APPROVE
        btnUnapprove.Enabled = GV_FRMEVENT_ALLOW_APPROVE
        btnDelete.Enabled = GV_FRMEVENT_ALLOW_EDIT

        Try
            Dim tn() As TreeNode = TreeView2.Nodes.Find(GV_SELECTED_EVENTID, True)
            Dim i As Integer = 0
            For i = 0 To tn.Length
                TreeView2.SelectedNode = tn(i)
            Next i
        Catch
            ''
        End Try
        TreeView2.Focus()

        TreeView2.CollapseAll()
        TreeView2.Width = 10
        TreeView2.Height = 10

        Dim CNnwind As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DSNWind As DataSet
        DSNWind = New DataSet()
        Dim DAEvent As New SqlClient.SqlDataAdapter("SELECT Event_msg, Event_ID,Status FROM Event where status <>'D' and pt_id1 = '" & GV_CUR_PATID & "'  order by date_tb " & GV_EVENT_SORT, CNnwind)
        CNnwind.Open()
        DSNWind.Clear()
        DAEvent.Fill(DSNWind, "dtEvent")


        Dim parentrow As DataRow
        Dim ParentTable As DataTable
        ParentTable = DSNWind.Tables("dtEvent")

        For Each parentrow In ParentTable.Rows
            EventComboBox1.Items.Add(parentrow.Item(0))
            'Dim parentnodeStatuts As TreeNode
            'parentnode = New TreeNode(parentrow.Item(0))
            'parentnodeStatuts = New TreeNode(parentrow.Item(0))
            'TreeView2.Nodes.Add(parentnode)
        Next parentrow

        'TreeView2.Nodes.Clear()

        'Determine if current event is locked by checking status P:lock A: unlock
        'If DSNWind.Tables("dtEvent").Rows(0)("status") = "P" Then
        'Me.lockAllFields()

        'End If

    End Sub

    Private Sub InitialTreeViewMsg()
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("sp_ListPatient_TreeView", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()
        myCommand.ExecuteNonQuery()
        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing
    End Sub


    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

    Private Sub btnTxRec_Click2(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If


        If TreeView2.SelectedNode Is Nothing Then
            MsgBox("Please select event.")
            Exit Sub
        Else
        End If

        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_TXID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            ' GV_SELECTED_TXID = TreeView2.SelectedNode.Name
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "T" Then GV_SELECTED_TXID = TreeView2.SelectedNode.Name Else GV_SELECTED_TXID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If

        'Dim oFrmTxRecommendation As New FrmTxRecommendation()
        'oFrmTxRecommendation.Show()
        FrmTxRecommendation.Close()
        FrmTxRecommendation.Show()
        FrmTxRecommendation.Focus()
    End Sub


    Private Sub btnTxRec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTxRec.Click
        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        'Added by cherwei to check for lock status and disallow adding new data if locked
        Dim vEventIDtemp As String
        vEventIDtemp = ""

        vEventIDtemp = TreeView2.SelectedNode.Name
        If vEventIDtemp.StartsWith("E") Then
        Else
            vEventIDtemp = TreeView2.SelectedNode.Parent.Name
        End If

        If IsApprovedEvent(vEventIDtemp) = True Then
            MsgBox("Please unlock event before adding new Tx Recommendation for Event: " + vEventIDtemp)
            Exit Sub
        End If

        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        If Trim(GV_SELECTED_EVENTID) = "" Then
            MsgBox("Please select event.")
            Exit Sub
        End If

        If TreeView2.SelectedNode Is Nothing Then
            MsgBox("Please select event.")
            Exit Sub
        Else

        End If


        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_TXID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "I" Then GV_SELECTED_TXID = TreeView2.SelectedNode.Name Else GV_SELECTED_TXID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If



        'Dim oFrmHistology As New FrmHistology()
        'oFrmHistology.Show()

        Dim selectedparenteventid As String
        Dim somename2 As String
        Dim totalcount As String


        selectedparenteventid = TreeView2.SelectedNode.Name
        somename2 = TreeView2.SelectedNode.Nodes.Count

        'check to see if the current selected row is Parent row 'E'
        If (selectedparenteventid.Trim.Substring(0, 1) = "E") Then
            'does not need further check as selected row is alreadly the parent node
        Else
            selectedparenteventid = TreeView2.SelectedNode.Parent.Name
        End If

        Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DATxRecommendationTemp As New SqlClient.SqlDataAdapter("SELECT Tx_msg, EVENT_ID, PT_Id1, recom_id , Status FROM recom where  status <>'D' and EVENT_ID = '" & selectedparenteventid & "'", CNnwind2)
        Dim DSNWindTemp As DataSet
        DSNWindTemp = New DataSet()
        DATxRecommendationTemp.Fill(DSNWindTemp, "dtTxRecommendationTemp")
        totalcount = DSNWindTemp.Tables(0).Rows.Count

        If (totalcount > 0) Then
            MsgBox("Please add new event. There is alreadly an existing TxRecommendation for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")
            Exit Sub
        End If

        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_TXID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            '   GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "T" Then GV_SELECTED_TXID = TreeView2.SelectedNode.Name Else GV_SELECTED_TXID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If




        'Dim oFrmTxRecommendation As New FrmTxRecommendation()
        'oFrmTxRecommendation.Show()
        FrmTxRecommendation.Close()
        FrmTxRecommendation.Show()
        FrmTxRecommendation.Focus()
    End Sub

    Private Sub TreeView2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
        If TreeView2.Nodes.Count > 0 Then
            'If TreeView2.SelectedNode.Level = 0 Then Button1_Click(sender, e)
            If TreeView2.SelectedNode.Level = 0 Then Select_Event()
            If TreeView2.SelectedNode.Level = 1 Then
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "H" Then btnMedHis_Click2(sender, e)
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "I" Then btnInvest_Click2(sender, e)
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "T" Then btnTxRec_Click2(sender, e)
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "S" Then btnHisology_Click2(sender, e)

            End If
            'If TreeView2.SelectedNode.Level = 2 Then btnHisology_Click(sender, e)
        End If
    End Sub
    Private Sub LoadCT()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  6", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxCT.DataSource = list
            Me.cbxCT.DisplayMember = "code_desc"
            Me.cbxCT.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadBone()

        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  8", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxBone.DataSource = list
            Me.cbxBone.DisplayMember = "code_desc"
            Me.cbxBone.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadM_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 207", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxM_Status.DataSource = list
            Me.cbxM_Status.DisplayMember = "Code_desc"
            Me.cbxM_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadN_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 200", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxN_Status.DataSource = list
            Me.cbxN_Status.DisplayMember = "Code_desc"
            Me.cbxN_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadErbB2()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 183", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxErbB2.DataSource = list
            Me.cbxErbB2.DisplayMember = "Code_desc"
            Me.cbxErbB2.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadReconstruction()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  544", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxReconstruction.DataSource = list
            Me.cbxReconstruction.DisplayMember = "Code_desc"
            Me.cbxReconstruction.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadCXR()

        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  5", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxCXR.DataSource = list
            Me.cbxCXR.DisplayMember = "Code_desc"
            Me.cbxCXR.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub FrmDiagnosis_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LocationChanged

    End Sub

    Private Sub FrmDiagnosis_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick

    End Sub

    Private Sub FrmDiagnosis_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown

    End Sub

    Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
        InitialTreeViewMsg()
        ListPatientDiagnosis()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim vEventID As String
        If TreeView2.SelectedNode Is Nothing = False Then
            Dim response As Integer
            Dim vDelID As String

            If TreeView2.Nodes.Count > 0 Then
                If TreeView2.SelectedNode.Level = 0 Then
                    vDelID = "E"
                    vEventID = TreeView2.SelectedNode.Name
                End If

                'If TreeView2.SelectedNode.Level = 1 Then
                'If TreeView2.SelectedNode.Name.Substring(0, 1) = "H" Then vDelID = "H"
                'If TreeView2.SelectedNode.Name.Substring(0, 1) = "I" Then vDelID = "I"
                'If TreeView2.SelectedNode.Name.Substring(0, 1) = "T" Then vDelID = "T"
                'If TreeView2.SelectedNode.Name.Substring(0, 1) = "S" Then vDelID = "S"
                'vEventID = TreeView2.SelectedNode.Parent.Name
                'End If

                If TreeView2.SelectedNode.Level = 2 Then
                    Dim vEventIDtemp As String
                    vEventIDtemp = ""
                    vEventIDtemp = TreeView2.SelectedNode.Parent.Parent.Name
                    If IsApprovedEvent(vEventIDtemp) = True Then
                        MsgBox("Locked event cannot be deleted.", MsgBoxStyle.Information, "Delete")
                        Exit Sub
                    End If

                    If IsApprovedEvent(vEventID) = True Then
                        MsgBox("Locked event cannot be deleted.", MsgBoxStyle.Information, "Delete")
                        Exit Sub
                    End If
                    response = MsgBox("Are you sure want to delete this record?", MsgBoxStyle.YesNo, "Delete")
                    If response = 7 Then
                        Exit Sub
                    End If
                    'if level2 is selected, need to check for child to determine if row is neoadjuvant or priortx for deletion
                    Dim currentlevel2row As String
                    currentlevel2row = TreeView2.SelectedNode.Text
                    vEventID = TreeView2.SelectedNode.Parent.Name
                    If (currentlevel2row.StartsWith("NEO")) Then
                        Dim currentHistoID2 As String
                        currentHistoID2 = TreeView2.SelectedNode.Parent.Name

                        'Retrieve the neo adjuvant data row ID
                        Dim vNeoadj As String
                        vNeoadj = ""
                        Dim SqlConnection1 As New SqlConnection()
                        SqlConnection1 = New SqlConnection(GV_CONNETION)
                        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
                        Dim sqlCmd = New SqlCommand("select Neoadj_ID from Neoadj where status <> 'D' and Histo_ID  = '" + currentHistoID2 + "'", SqlConnection1)
                        Try
                            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
                            Do While objReader.Read
                                vNeoadj = IIf(IsDBNull(objReader("Neoadj_ID")), "", objReader("Neoadj_ID"))
                            Loop

                        Catch ex As Exception
                            MsgBox(ex.Source)
                        End Try

                        sqlCmd.Cancel()
                        SqlConnection1.Close()
                        sqlCmd = Nothing
                        SqlConnection1.Close()

                        'update the neoadj to Delete status
                        '' Dim myCommand1 As SqlCommand
                        ''Dim SqlConn1 As New SqlConnection()
                        ''SqlConn1 = New SqlConnection(GV_CONNETION)

                        'myCommand1 = New SqlCommand("delete from neoadj where Histo_ID = '" + currentHistoID2 + "'", SqlConn1)
                        ''myCommand1 = New SqlCommand("update neoadj set status = 'D' where Neoadj_ID = '" + vNeoadj + "'", SqlConn1)
                        ''myCommand1.CommandType = CommandType.Text
                        ''SqlConn1.Open()
                        ''myCommand1.ExecuteNonQuery()
                        ''SqlConn1.Close()



                        'updates the log file and the actual record with the latest info
                        Dim myCommand5 As SqlCommand
                        Dim SqlConn5 As New SqlConnection()
                        SqlConn5 = New SqlConnection(GV_CONNETION)
                        myCommand5 = New SqlCommand("spDelNeadjuvant", SqlConn5)
                        myCommand5.CommandType = CommandType.StoredProcedure
                        SqlConn5.Open()

                        myCommand5.Parameters.Add("@Neoadj_ID", SqlDbType.VarChar)
                        myCommand5.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
                        myCommand5.Parameters("@Neoadj_ID").Value = vNeoadj 'GV_SELECTED_NEOADJID
                        myCommand5.Parameters("@EnteredBy").Value = GV_USER 'GV_USER
                        myCommand5.ExecuteNonQuery()

                        myCommand5.Cancel()
                        SqlConn5.Close()
                        myCommand5 = Nothing
                        SqlConn5 = Nothing
                        ''turned off by cherwei to prevent diag form to close and go back to main page
                        'Close()   
                        disableAllFields()
                        'TreeView2.Focus()

                    Else

                        'Retrieve the priortx data row ID

                        Dim currentHistoID2 As String
                        currentHistoID2 = TreeView2.SelectedNode.Parent.Name
                        Dim vPrioradj As String
                        vPrioradj = ""
                        Dim SqlConnection1 As New SqlConnection()
                        SqlConnection1 = New SqlConnection(GV_CONNETION)
                        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
                        Dim sqlCmd = New SqlCommand("select PriorTx_ID from PriorTx where status <> 'D' and Histo_ID  = '" + currentHistoID2 + "'", SqlConnection1)
                        Try
                            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
                            Do While objReader.Read
                                vPrioradj = IIf(IsDBNull(objReader("PriorTx_ID")), "", objReader("PriorTx_ID"))
                            Loop

                        Catch ex As Exception
                            MsgBox(ex.Source)
                        End Try

                        sqlCmd.Cancel()
                        SqlConnection1.Close()
                        sqlCmd = Nothing
                        SqlConnection1.Close()

                        'updates the log file and the actual record with the latest info
                        Dim myCommand6 As SqlCommand
                        Dim SqlConn6 As New SqlConnection()
                        SqlConn6 = New SqlConnection(GV_CONNETION)
                        myCommand6 = New SqlCommand("spDelPriorTx", SqlConn6)
                        myCommand6.CommandType = CommandType.StoredProcedure
                        SqlConn6.Open()

                        myCommand6.Parameters.Add("@PriorTx_ID", SqlDbType.VarChar)
                        myCommand6.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
                        myCommand6.Parameters("@PriorTx_ID").Value = vPrioradj 'GV_SELECTED_NEOADJID
                        myCommand6.Parameters("@EnteredBy").Value = GV_USER 'GV_USER
                        myCommand6.ExecuteNonQuery()

                        myCommand6.Cancel()
                        SqlConn6.Close()
                        myCommand6 = Nothing
                        SqlConn6 = Nothing
                        ''Close()

                        ''Dim myCommand1 As SqlCommand
                        ''Dim SqlConn1 As New SqlConnection()
                        ''SqlConn1 = New SqlConnection(GV_CONNETION)
                        ''Dim currentHistoID2 As String
                        ''currentHistoID2 = TreeView2.SelectedNode.Name
                        'myCommand1 = New SqlCommand("delete from priortx where Histo_ID = '" + currentHistoID2 + "'", SqlConn1)
                        ''myCommand1 = New SqlCommand("update priortx set status = 'D' where Histo_ID = '" + currentHistoID2 + "'", SqlConn1)
                        ''myCommand1.CommandType = CommandType.Text
                        ''SqlConn1.Open()
                        ''myCommand1.ExecuteNonQuery()
                        ''SqlConn1.Close()

                    End If
                    'if (currentlevel2row.IndexOf
                    ' TreeView2.SelectedNode.Remove()
                    btnRefresh_Click(sender, e)
                    'TreeView2.Focus()
                    disableAllFields()
                    Exit Sub
                End If
            End If

            If IsApprovedEvent(vEventID) = True Then
                MsgBox("Locked event cannot be deleted.", MsgBoxStyle.Information, "Delete")
                Exit Sub
            End If
            response = MsgBox("Are you sure want to delete this record?", MsgBoxStyle.YesNo, "Delete")
            If response = 7 Then
                Exit Sub  'exits the function
            End If

            Dim myCommand As SqlCommand
            Dim SqlConn As New SqlConnection()
            SqlConn = New SqlConnection(GV_CONNETION)
            'event
            If vDelID = "E" Then
                myCommand = New SqlCommand("spDelEvent", SqlConn)
                myCommand.CommandType = CommandType.StoredProcedure
                SqlConn.Open()

                myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
                myCommand.Parameters("@Event_ID").Value = TreeView2.SelectedNode.Name
                myCommand.Parameters("@EnteredBy").Value = GV_USER
                myCommand.ExecuteNonQuery()
            End If

            'History
            If vDelID = "H" Then
                myCommand = New SqlCommand("spDelHistory", SqlConn)
                myCommand.CommandType = CommandType.StoredProcedure
                SqlConn.Open()

                myCommand.Parameters.Add("@History_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
                myCommand.Parameters("@History_ID").Value = TreeView2.SelectedNode.Name
                myCommand.Parameters("@EnteredBy").Value = GV_USER
                myCommand.ExecuteNonQuery()
            End If

            'Investigation
            If vDelID = "I" Then
                myCommand = New SqlCommand("spDelInvestigation", SqlConn)
                myCommand.CommandType = CommandType.StoredProcedure
                SqlConn.Open()

                myCommand.Parameters.Add("@inv_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
                myCommand.Parameters("@inv_ID").Value = TreeView2.SelectedNode.Name
                myCommand.Parameters("@EnteredBy").Value = GV_USER
                myCommand.ExecuteNonQuery()

            End If

            'Investigation
            If vDelID = "T" Then
                myCommand = New SqlCommand("spDelTxRecommendation", SqlConn)
                myCommand.CommandType = CommandType.StoredProcedure
                SqlConn.Open()

                myCommand.Parameters.Add("@recom_id", SqlDbType.VarChar)
                myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
                myCommand.Parameters("@recom_id").Value = TreeView2.SelectedNode.Name
                myCommand.Parameters("@EnteredBy").Value = GV_USER
                myCommand.ExecuteNonQuery()

            End If

            'Histology
            If vDelID = "S" Then
                'Modified by cherwei to temporary use sql command instead of stored procedures 
                'if histology check child tables Neoadj and PriorTx to ensure child records are removed 1st
                Dim currentHistoID As String
                currentHistoID = TreeView2.SelectedNode.Name


                'Dim DANeoAdj As New SqlClient.SqlDataAdapter("select * from neoadj where Histo_ID = '" + currentHistoID + "'", SqlConn)
                Dim DANeoAdj As New SqlClient.SqlDataAdapter("select * from neoadj where status <> 'D' and Histo_ID = '" + currentHistoID + "'", SqlConn)
                Dim DSNeoAdj As DataSet
                DSNeoAdj = New DataSet()
                SqlConn.Open()
                DANeoAdj.Fill(DSNeoAdj, "dtneoadj")

                Dim DAPriorTx As New SqlClient.SqlDataAdapter("select * from priortx where status <> 'D' and Histo_ID = '" + currentHistoID + "'", SqlConn)
                Dim DSPriorTx As DataSet
                DSPriorTx = New DataSet()
                DAPriorTx.Fill(DSPriorTx, "dtpriortx")

                SqlConn.Close()

                If (DSNeoAdj.Tables("dtneoadj").Rows.Count > 0) Then
                    'myCommand = New SqlCommand("delete from neoadj where Histo_ID = '" + currentHistoID + "'", SqlConn)
                    myCommand = New SqlCommand("update neoadj set status = 'D' where status = 'A' and Histo_ID = '" + currentHistoID + "'", SqlConn)
                    myCommand.CommandType = CommandType.Text
                    SqlConn.Open()
                    myCommand.ExecuteNonQuery()
                    SqlConn.Close()
                End If

                If (DSPriorTx.Tables("dtpriortx").Rows.Count > 0) Then
                    'delete the child records
                    'myCommand = New SqlCommand("delete from priortx where Histo_ID = '" + currentHistoID + "'", SqlConn)
                    myCommand = New SqlCommand("update priortx set status = 'D' where status = 'A' and Histo_ID = '" + currentHistoID + "'", SqlConn)
                    myCommand.CommandType = CommandType.Text
                    SqlConn.Open()
                    myCommand.ExecuteNonQuery()
                    SqlConn.Close()
                End If



                'delete the child records
                If TreeView2.SelectedNode.Level = 2 Then

                Else
                    'myCommand = New SqlCommand("delete from histology where Histo_ID = '" + currentHistoID + "'", SqlConn)
                    myCommand = New SqlCommand("update histology set status = 'D' where status = 'A' and Histo_ID = '" + currentHistoID + "'", SqlConn)
                    myCommand.CommandType = CommandType.Text
                    SqlConn.Open()
                    myCommand.ExecuteNonQuery()
                    SqlConn.Close()
                End If



                'myCommand = New SqlCommand("spDelHistology", SqlConn)
                'myCommand.CommandType = CommandType.StoredProcedure
                'SqlConn.Open()

                'myCommand.Parameters.Add("@Histo_ID", SqlDbType.VarChar)
                'myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
                'myCommand.Parameters("@Histo_ID").Value = TreeView2.SelectedNode.Name
                'myCommand.Parameters("@EnteredBy").Value = GV_USER
                'myCommand.ExecuteNonQuery()

            End If

            myCommand.Cancel()
            SqlConn.Close()
            myCommand = Nothing
            SqlConn = Nothing
            TreeView2.SelectedNode.Remove()
            btnRefresh_Click(sender, e)
            TreeView2.CollapseAll()

            'myCommand = New SqlCommand("spDelHistology", SqlConn)
            'myCommand.CommandType = CommandType.StoredProcedure
            'SqlConn.Open()

            'myCommand.Parameters.Add("@Histo_ID", SqlDbType.VarChar)
            'myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
            'myCommand.Parameters("@Histo_ID").Value = TreeView2.SelectedNode.Name
            'myCommand.Parameters("@EnteredBy").Value = GV_USER
            'myCommand.ExecuteNonQuery()

            TreeView2.Focus()
            MsgBox("Event '" + vEventID + "' deleted successfully.")
        End If

        'myCommand.Cancel()
        'SqlConn.Close()
        'myCommand = Nothing
        'SqlConn = Nothing
        'TreeView2.SelectedNode.Remove()
        ' btnRefresh_Click(sender, e)
        'End If


    End Sub
    Private Sub LoadPR_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 178", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxPR_Status.DataSource = list
            Me.cbxPR_Status.DisplayMember = "Code_desc"
            Me.cbxPR_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadHistoDx()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  118", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxHistoDx.DataSource = list
            Me.cbxHistoDx.DisplayMember = "code_desc"
            Me.cbxHistoDx.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadTypeBiopsy()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  112", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxTypeBiopsy.DataSource = list
            Me.cbxTypeBiopsy.DisplayMember = "code_desc"
            Me.cbxTypeBiopsy.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadER_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 173", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxER_Status.DataSource = list
            Me.cbxER_Status.DisplayMember = "Code_desc"
            Me.cbxER_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadSentinel_LN()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  547", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxSentinel_LN.DataSource = list
            Me.cbxSentinel_LN.DisplayMember = "Code_desc"
            Me.cbxSentinel_LN.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadSentinelLNPolarity()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  548", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxSentinelLNPolarity.DataSource = list
            Me.cbxSentinelLNPolarity.DisplayMember = "Code_desc"
            Me.cbxSentinelLNPolarity.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()

    End Sub
    Private Sub LoadRadialMargin()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  165", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxradialMargin.DataSource = list
            Me.cbxradialMargin.DisplayMember = "Code_desc"
            Me.cbxradialMargin.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadMarginDCIS()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  162", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cboxMarginDCIS.DataSource = list
            Me.cboxMarginDCIS.DisplayMember = "Code_desc"
            Me.cboxMarginDCIS.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadMargin_invasive()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  159", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxMargin_invasive.DataSource = list
            Me.cbxMargin_invasive.DisplayMember = "Code_desc"
            Me.cbxMargin_invasive.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadLymhovascular()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  154", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxLymhovascular.DataSource = list
            Me.cbxLymhovascular.DisplayMember = "Code_desc"
            Me.cbxLymhovascular.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadDCIS()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  260", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_Desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_Desc")), "", objReader("Code_Desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxDCIS.DataSource = list
            Me.cbxDCIS.DisplayMember = "Code_Desc"
            Me.cbxDCIS.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadcT_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 274", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxcT_Status.DataSource = list
            Me.cbxcT_Status.DisplayMember = "Code_desc"
            Me.cbxcT_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadTypeSurg()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  124", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxTypeSurg.DataSource = list
            Me.cbxTypeSurg.DisplayMember = "Code_desc"
            Me.cbxTypeSurg.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadHistoGrade()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  149", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxHistoGrade.DataSource = list
            Me.cbxHistoGrade.DisplayMember = "Code_desc"
            Me.cbxHistoGrade.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadHistoType()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  132", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxHistoType.DataSource = list
            Me.cbxHistoType.DisplayMember = "code_desc"
            Me.cbxHistoType.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadClinAxillaryLN()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  107", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxClinAxillaryLN.DataSource = list
            Me.cbxClinAxillaryLN.DisplayMember = "code_desc"
            Me.cbxClinAxillaryLN.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadExtChestWall()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  103", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_Desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_Desc")), "", objReader("Code_Desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxExtChestWall.DataSource = list
            Me.cbxExtChestWall.DisplayMember = "Code_Desc"
            Me.cbxExtChestWall.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadBTB_Recommend()

        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 306", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxBTBRecommend.DataSource = list
            Me.cbxBTBRecommend.DisplayMember = "code_desc"
            Me.cbxBTBRecommend.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Function IsApprovedEvent(ByVal vEventID) As Boolean
        Dim vStatus As String = ""
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("select * from Event where event_id = '" & vEventID & "'", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Do While objReader.Read
                vStatus = IIf(IsDBNull(objReader("Status")), "", objReader("Status"))
            Loop

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()

        If vStatus = "P" Then  'P status means locked
            IsApprovedEvent = True
            Me.lockAllFields()

        Else
            IsApprovedEvent = False
        End If
    End Function
    Private Sub DeleteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteToolStripMenuItem.Click
        btnDelete_Click(sender, e)
    End Sub

    Private Sub ContextMenuStrip1_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening
        If TreeView2.SelectedNode Is Nothing Then
            EditToolStripMenuItem.Enabled = False
            DeleteToolStripMenuItem.Enabled = False
            ApproveToolStripMenuItem.Enabled = False
        End If
    End Sub

    Private Sub ApprovalToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApproveToolStripMenuItem.Click
        btnApprove_Click(sender, e)
    End Sub

    Private Sub EditToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditToolStripMenuItem.Click
        TreeView2_DoubleClick(sender, e)
    End Sub

    Private Sub btnApprove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApprove.Click
        If TreeView2.SelectedNode Is Nothing Then
            Exit Sub
        End If
        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If

        If TreeView2.SelectedNode.Level = 2 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Parent.Name()
            GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Parent.Name()
        End If

        If IsApprovedEvent(GV_SELECTED_EVENTID) = True Then
            MsgBox("Event was locked.", MsgBoxStyle.Information, "Lock")
            Exit Sub
        End If
        GV_APPROVAL_TYPE = "LOCK"
        FrmApprove.Text = "Lock Event..."
        FrmApprove.ShowDialog()
        FrmApprove.TxtPw.Focus()




    End Sub

    Private Sub MoveToEventToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MoveToEventToolStripMenuItem.Click
        If TreeView2.SelectedNode Is Nothing Then
            Exit Sub
        End If
        If TreeView2.Nodes.Count > 0 Then
            If TreeView2.SelectedNode.Level = 0 Then
                MsgBox("Event not allow to change.", MsgBoxStyle.Information, "Move")
                Exit Sub
            End If

            If TreeView2.SelectedNode.Level = 1 Then
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "H" Then GV_SELECTED_TYPE = "H"
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "I" Then GV_SELECTED_TYPE = "I"
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "T" Then GV_SELECTED_TYPE = "T"
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "S" Then GV_SELECTED_TYPE = "S"
                GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name
                GV_SELECTED_TYPE_ID = TreeView2.SelectedNode.Name
            End If
        End If


        If IsApprovedEvent(GV_SELECTED_EVENTID) = True Then
            MsgBox("Locked event cannot be changed.", MsgBoxStyle.Information, "Move")
            Exit Sub
        End If

        GV_MOVE_COPY_TYPE = "MOVE"
        FrmMove.Close()
        FrmMove.Show()
        FrmMove.Text = "Move to..."
        FrmMove.Focus()
    End Sub

    Private Sub CopyToEventToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToEventToolStripMenuItem.Click
        If TreeView2.SelectedNode Is Nothing Then
            Exit Sub
        End If
        If TreeView2.Nodes.Count > 0 Then
            If TreeView2.SelectedNode.Level = 0 Then
                MsgBox("Event not allow to change.", MsgBoxStyle.Information, "Copy")
                Exit Sub
            End If

            If TreeView2.SelectedNode.Level = 1 Then
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "H" Then GV_SELECTED_TYPE = "H"
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "I" Then GV_SELECTED_TYPE = "I"
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "T" Then GV_SELECTED_TYPE = "T"
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "S" Then GV_SELECTED_TYPE = "S"
                GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name
                GV_SELECTED_TYPE_ID = TreeView2.SelectedNode.Name
            End If
        End If

        GV_MOVE_COPY_TYPE = "COPY"
        FrmMove.Close()
        FrmMove.Show()
        FrmMove.Text = "Copy to..."
        FrmMove.Focus()
    End Sub

    Private Sub SortEventByAscdecToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SortEventByAscdecToolStripMenuItem.Click
        If GV_EVENT_SORT = "ASC" Then GV_EVENT_SORT = "DESC" Else GV_EVENT_SORT = "ASC"
        ListPatientDiagnosis()

    End Sub

    Private Sub btnUnapprove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnapprove.Click
        If TreeView2.SelectedNode Is Nothing Then
            Exit Sub
        End If
        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If

        If TreeView2.SelectedNode.Level = 2 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Parent.Name()
            GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Parent.Name()
        End If

        Dim response As Integer

        If IsApprovedEvent(GV_SELECTED_EVENTID) = False Then
            MsgBox("Event is unlock.", MsgBoxStyle.Information, "Unlock")
            Exit Sub
        End If
        GV_APPROVAL_TYPE = "UNLOCK"
        FrmApprove.Text = "Unlock Event..."
        FrmApprove.ShowDialog()
        FrmApprove.TxtPw.Focus()

    End Sub

    Private Sub UnapproveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UnapproveToolStripMenuItem.Click
        btnUnapprove_Click(sender, e)
    End Sub

    Function Select_Event()
        If TreeView2.SelectedNode Is Nothing Then
            GV_SELECTED_EVENTID = ""
        Else
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name

            'load the data into the tab pages
            Me.displayPatientData(GV_SELECTED_EVENTID)

        End If
        FrmEvent.Close()
        FrmEvent.Show()
        FrmEvent.Focus()
    End Function
    Private Sub LoadFamilyHistory()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 2", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxHistory.DataSource = list
            Me.cbxHistory.DisplayMember = "code_desc"
            Me.cbxHistory.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadMenstrualStatus()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 1", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxStatus.DataSource = list
            Me.cbxStatus.DisplayMember = "code_desc"
            Me.cbxStatus.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub


    Private Sub btnHisology_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHisology.DoubleClick

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        'check if event is locked, enable/disable save button
        If Trim(GV_SELECTED_EVENTID) = "" Then
            'btnSave.Enabled = False
        Else
            'btnSave.Enabled = True
        End If

        'Perform the save functions
        'save function for event
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertEvent", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@date_tb", SqlDbType.DateTime)
        myCommand.Parameters.Add("@date_cn", SqlDbType.DateTime)
        myCommand.Parameters.Add("@doc_inc", SqlDbType.VarChar)
        myCommand.Parameters.Add("@case_type", SqlDbType.VarChar)
        myCommand.Parameters.Add("@brst_screen", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Metasyn_Status", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Metasynchronous", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

        'check n retrieve current eventid on the form, if eventid is empty, gv_isedit = false else gv_isedit = true
        'If Trim(lblEvent.Text).IndexOf("E") = -1 Then
        'gv_isedit = False
        'Else
        'gv_isedit = True
        'End If
        If Trim(GV_SELECTED_INVESTID).IndexOf("E") = -1 Then
            gv_isedit = False
        Else
            gv_isedit = True
        End If

        If gv_isedit = True Then
            myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
        Else
            myCommand.Parameters("@Event_ID").Value = "0"
        End If
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@date_tb").Value = FormatDateTime(DOB.Value, DateFormat.ShortDate)
        myCommand.Parameters("@date_cn").Value = FormatDateTime(DateTimePicker1.Value, DateFormat.ShortDate)
        myCommand.Parameters("@doc_inc").Value = Trim(cbxDoctor.Text)
        myCommand.Parameters("@case_type").Value = Trim(cbxCaseType.Text)
        myCommand.Parameters("@brst_screen").Value = Trim(cbxLaterality.Text)
        myCommand.Parameters("@Metasyn_Status").Value = Trim(CboxMeta.Text)
        myCommand.Parameters("@Metasynchronous").Value = Trim(CboxMetasEvent.SelectedValue)
        myCommand.Parameters("@EnteredBy").Value = GV_USER

        'check again, if patient data is in database, do not execute
        Dim vPatID As String = ""
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()

        'Dim sqlCmd = New SqlCommand("select ptNRIC from PATIENTS where ptNRIC = '" & PatNRIC.Text & "'", SqlConnection1)
        'Try
        'Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
        'Do While objReader.Read
        'vPatID = IIf(IsDBNull(objReader("ptNRIC")), "", objReader("ptNRIC"))
        'Loop

        'Catch ex As Exception
        'MsgBox(ex.Source)
        'End Try


        If LTrim(RTrim(vPatID)) = "" Then
            MsgBox("Please load an existing event first")
            'btnSave.Enabled = False
            'sqlCmd.Cancel()
            'SqlConnection1.Close()
            'sqlCmd = Nothing
            SqlConnection1.Close()
        Else
            myCommand.ExecuteNonQuery()

            ' perform the save procedures to other tables 
            'save function for investigation
            SqlConn = New SqlConnection(GV_CONNETION)
            myCommand = New SqlCommand("spInsertInvestigation", SqlConn)
            myCommand.CommandType = CommandType.StoredProcedure
            SqlConn.Open()

            myCommand.Parameters.Add("@Inv_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@CXR", SqlDbType.VarChar)
            myCommand.Parameters.Add("@CT", SqlDbType.VarChar)
            myCommand.Parameters.Add("@BoneScan", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

            If Trim(GV_SELECTED_INVESTID).IndexOf("I") = -1 Then
                gv_isedit = False
            Else
                gv_isedit = True
            End If

            If gv_isedit = True Then
                myCommand.Parameters("@Inv_ID").Value = GV_SELECTED_INVESTID
            Else
                myCommand.Parameters("@Inv_ID").Value = "0"
            End If
            myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
            myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
            myCommand.Parameters("@CXR").Value = Trim(cbxCXR.SelectedValue)
            myCommand.Parameters("@CT").Value = Trim(cbxCT.SelectedValue)
            myCommand.Parameters("@BoneScan").Value = Trim(cbxBone.SelectedValue)
            myCommand.Parameters("@Notes").Value = Trim(RichTextNotes.Text)
            myCommand.Parameters("@EnteredBy").Value = GV_USER

            If Trim(GV_SELECTED_INVESTID).IndexOf("I") = -1 Then

            Else
                myCommand.ExecuteNonQuery()

            End If

            myCommand.Cancel()
            SqlConn.Close()
            myCommand = Nothing
            SqlConn = Nothing


            'save function for tx recommendation details

            SqlConn = New SqlConnection(GV_CONNETION)
            myCommand = New SqlCommand("spInsertTxRecommendation", SqlConn)
            myCommand.CommandType = CommandType.StoredProcedure
            SqlConn.Open()

            myCommand.Parameters.Add("@recom_id", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@recommendation", SqlDbType.VarChar)
            myCommand.Parameters.Add("@chemotherapy", SqlDbType.Bit)
            myCommand.Parameters.Add("@hormonaltherapy", SqlDbType.Bit)
            myCommand.Parameters.Add("@radiotherapy", SqlDbType.Bit)
            myCommand.Parameters.Add("@surgery", SqlDbType.Bit)
            myCommand.Parameters.Add("@immunotherapy", SqlDbType.Bit)
            myCommand.Parameters.Add("@recommend_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@form_complete", SqlDbType.Bit)
            myCommand.Parameters.Add("@update_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

            If Trim(GV_SELECTED_TXID).IndexOf("T") = -1 Then
                gv_isedit = False
            Else
                gv_isedit = True
            End If

            If gv_isedit = True Then
                myCommand.Parameters("@recom_id").Value = GV_SELECTED_TXID
            Else
                myCommand.Parameters("@recom_id").Value = "0"

            End If
            myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
            myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
            myCommand.Parameters("@recommendation").Value = Trim(cbxBTBRecommend.Text)
            myCommand.Parameters("@chemotherapy").Value = cboxChemo.Checked
            myCommand.Parameters("@hormonaltherapy").Value = cboxHormonal.Checked
            myCommand.Parameters("@radiotherapy").Value = cboxRadio.Checked
            myCommand.Parameters("@surgery").Value = cboxSurgery.Checked
            myCommand.Parameters("@immunotherapy").Value = cboxTargerted.Checked
            myCommand.Parameters("@recommend_notes").Value = Trim(txtComments.Text)
            myCommand.Parameters("@form_complete").Value = cboxComplete.Checked
            myCommand.Parameters("@update_notes").Value = Trim(txtNotes.Text)
            myCommand.Parameters("@EnteredBy").Value = GV_USER
            If Trim(GV_SELECTED_TXID).IndexOf("T") = -1 Then

            Else
                myCommand.ExecuteNonQuery()
            End If

            myCommand.Cancel()
            SqlConn.Close()
            myCommand = Nothing
            SqlConn = Nothing


            'save histology table
            Try
                SqlConn = New SqlConnection(GV_CONNETION)
                myCommand = New SqlCommand("spInsertHistology", SqlConn)
                myCommand.CommandType = CommandType.StoredProcedure
                SqlConn.Open()

                myCommand.Parameters.Add("@Histo_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
                myCommand.Parameters.Add("@clin_tum_size", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Ext_cw", SqlDbType.VarChar)
                myCommand.Parameters.Add("@clin_ax_ln", SqlDbType.VarChar)
                myCommand.Parameters.Add("@biopsy_Type", SqlDbType.VarChar)
                myCommand.Parameters.Add("@date_biopsy", SqlDbType.DateTime)
                myCommand.Parameters.Add("@histo_Dx", SqlDbType.VarChar)
                myCommand.Parameters.Add("@date_pri_surg", SqlDbType.DateTime)
                myCommand.Parameters.Add("@surg_type", SqlDbType.VarChar)
                myCommand.Parameters.Add("@reconstruction", SqlDbType.VarChar)
                myCommand.Parameters.Add("@chk_Neoadj", SqlDbType.Bit)
                myCommand.Parameters.Add("@chk_Local", SqlDbType.Bit)
                myCommand.Parameters.Add("@chk_Systemic", SqlDbType.Bit)
                myCommand.Parameters.Add("@add_physurg_notes", SqlDbType.VarChar)
                myCommand.Parameters.Add("@other_histo_notes", SqlDbType.VarChar)
                myCommand.Parameters.Add("@histo_tum_size", SqlDbType.VarChar)
                myCommand.Parameters.Add("@histo_type", SqlDbType.VarChar)
                myCommand.Parameters.Add("@histo_grade", SqlDbType.VarChar)
                myCommand.Parameters.Add("@ass_dcis", SqlDbType.VarChar)
                myCommand.Parameters.Add("@lymphovas_inv", SqlDbType.VarChar)
                myCommand.Parameters.Add("@marg_inv_ca", SqlDbType.VarChar)
                myCommand.Parameters.Add("@marg_dcis", SqlDbType.VarChar)
                myCommand.Parameters.Add("@closest_marg", SqlDbType.VarChar)
                myCommand.Parameters.Add("@closest_marg_size", SqlDbType.VarChar)
                myCommand.Parameters.Add("@deep_marg_size", SqlDbType.VarChar)
                myCommand.Parameters.Add("@SLN_1", SqlDbType.VarChar)
                myCommand.Parameters.Add("@ax_ln_pos", SqlDbType.VarChar)
                myCommand.Parameters.Add("@ax_ln_fd", SqlDbType.VarChar)
                myCommand.Parameters.Add("@er_status", SqlDbType.VarChar)
                myCommand.Parameters.Add("@pr_status", SqlDbType.VarChar)
                myCommand.Parameters.Add("@c_erbb2_status", SqlDbType.VarChar)
                myCommand.Parameters.Add("@t_stage_6", SqlDbType.VarChar)
                myCommand.Parameters.Add("@n_stage_6", SqlDbType.VarChar)
                myCommand.Parameters.Add("@m_stage_6", SqlDbType.VarChar)
                myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

                If Trim(GV_SELECTED_HISTOLOGYID).IndexOf("S") = -1 Then
                    gv_isedit = False
                Else
                    gv_isedit = True
                End If

                If gv_isedit = True Then
                    myCommand.Parameters("@Histo_ID").Value = GV_SELECTED_HISTOLOGYID
                Else
                    myCommand.Parameters("@Histo_ID").Value = "0"
                End If
                myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
                myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
                myCommand.Parameters("@clin_tum_size").Value = Trim(txtTumourSize.Text)
                myCommand.Parameters("@Ext_cw").Value = Trim(cbxExtChestWall.Text)
                myCommand.Parameters("@clin_ax_ln").Value = Trim(cbxClinAxillaryLN.Text)
                myCommand.Parameters("@biopsy_Type").Value = Trim(cbxTypeBiopsy.Text)
                myCommand.Parameters("@date_biopsy").Value = dtDateBiopsy.Value
                myCommand.Parameters("@histo_Dx").Value = Trim(cbxHistoDx.Text)
                myCommand.Parameters("@date_pri_surg").Value = DtPrisurg.Value
                myCommand.Parameters("@surg_type").Value = Trim(cbxTypeSurg.Text)
                myCommand.Parameters("@reconstruction").Value = Trim(cbxReconstruction.Text)
                myCommand.Parameters("@chk_Neoadj").Value = cboxNeoadjuvant.Checked
                myCommand.Parameters("@chk_Local").Value = cboxLocalRec.Checked
                myCommand.Parameters("@chk_Systemic").Value = cboxSystemic.Checked
                myCommand.Parameters("@add_physurg_notes").Value = Trim(txtPhysicalNotes.Text)
                myCommand.Parameters("@other_histo_notes").Value = Trim(txtHistoNotes.Text)
                myCommand.Parameters("@histo_tum_size").Value = Trim(txtHisto_TumourSize.Text)
                myCommand.Parameters("@histo_type").Value = Trim(cbxHistoType.Text)
                myCommand.Parameters("@histo_grade").Value = Trim(cbxHistoGrade.Text)
                myCommand.Parameters("@ass_dcis").Value = Trim(cbxDCIS.Text)
                myCommand.Parameters("@lymphovas_inv").Value = Trim(cbxLymhovascular.Text)
                myCommand.Parameters("@marg_inv_ca").Value = Trim(cbxMargin_invasive.Text)
                myCommand.Parameters("@marg_dcis").Value = Trim(cboxMarginDCIS.Text)
                myCommand.Parameters("@closest_marg").Value = Trim(cbxradialMargin.Text)
                myCommand.Parameters("@closest_marg_size").Value = Trim(txtRadialMargin.Text)
                myCommand.Parameters("@deep_marg_size").Value = Trim(txtDeepMargin.Text)
                myCommand.Parameters("@SLN_1").Value = Trim(cbxSentinel_LN.Text)
                myCommand.Parameters("@ax_ln_pos").Value = Trim(txtTotal_Ax_LN_Postive.Text)
                myCommand.Parameters("@ax_ln_fd").Value = Trim(txtTotal_Ax_LN_Found.Text)
                myCommand.Parameters("@er_status").Value = Trim(cbxER_Status.Text)
                myCommand.Parameters("@pr_status").Value = Trim(cbxPR_Status.Text)
                myCommand.Parameters("@c_erbb2_status").Value = Trim(cbxErbB2.Text)
                myCommand.Parameters("@t_stage_6").Value = Trim(cbxcT_Status.Text)
                myCommand.Parameters("@n_stage_6").Value = Trim(cbxN_Status.Text)
                myCommand.Parameters("@m_stage_6").Value = Trim(cbxM_Status.Text)
                myCommand.Parameters("@EnteredBy").Value = GV_USER
                If Trim(GV_SELECTED_HISTOLOGYID).IndexOf("S") = -1 Then

                Else
                    myCommand.ExecuteNonQuery()


                End If

                myCommand.Cancel()
                SqlConn.Close()
                myCommand = Nothing
                SqlConn = Nothing
            Catch ex As Exception
                MsgBox(ex.Message)

            End Try

            'save history table
            SqlConn = New SqlConnection(GV_CONNETION)
            myCommand = New SqlCommand("spInsertHistory", SqlConn)
            myCommand.CommandType = CommandType.StoredProcedure
            SqlConn.Open()

            myCommand.Parameters.Add("@History_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@FamilyHistory", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Menstrual", SqlDbType.VarChar)
            myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

            If Trim(GV_SELECTED_HISTORYID).IndexOf("H") = -1 Then
                gv_isedit = False
            Else
                gv_isedit = True
            End If

            If gv_isedit = True Then
                myCommand.Parameters("@History_ID").Value = GV_SELECTED_HISTORYID
            Else
                myCommand.Parameters("@History_ID").Value = "0"
            End If
            myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
            myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
            myCommand.Parameters("@FamilyHistory").Value = Trim(cbxHistory.Text)
            myCommand.Parameters("@Menstrual").Value = Trim(cbxStatus.Text)
            myCommand.Parameters("@EnteredBy").Value = GV_USER

            If Trim(GV_SELECTED_HISTORYID).IndexOf("H") = -1 Then

            Else
                myCommand.ExecuteNonQuery()
            End If

            myCommand.Cancel()
            SqlConn.Close()
            myCommand = Nothing
            SqlConn = Nothing

        End If


        'SqlConn.Close()
        'myCommand = Nothing
        'SqlConn = Nothing



        'If ValidateHistology() = True Then
        'SaveHistology()
        'Panel2.Enabled = False
        'Close()
        'FrmDiagnosis.Close()
        'FrmDiagnosis.Show()
        'FrmDiagnosis.Focus()
        'Else

        'End If


        'TabControl1.SelectedIndex = 1
        'TabControl1.TabPages.Add("tabPage")
        'Treeview2

    End Sub
    Private Sub CboxMeta_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboxMeta.SelectedIndexChanged
        If CboxMeta.Text = "Yes" Then
            CboxMetasEvent.Enabled = True
        Else
            CboxMetasEvent.Enabled = False
            CboxMetasEvent.SelectedValue = ""
        End If
    End Sub

    Private Sub FrmDiagnosis_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged

    End Sub

    Private Sub TreeView2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If TreeView2.Nodes.Count = 0 Then
            'MsgBox("Please add new event.")
            Exit Sub
        End If

        'Added by cherwei to check for lock status and disallow adding new data if locked
        Dim vEventIDtemp As String
        vEventIDtemp = ""

        vEventIDtemp = TreeView2.SelectedNode.Name
        If vEventIDtemp.StartsWith("E") Then
        Else
            vEventIDtemp = TreeView2.SelectedNode.Parent.Name
        End If

        'If IsApprovedEvent(vEventIDtemp) = True Then
        'MsgBox("Please unlock event before adding new Histology for Event: " + vEventIDtemp)
        'Exit Sub
        'End If

        If TreeView2.Nodes.Count = 0 Then
            'MsgBox("Please add new event.")
            Exit Sub
        End If

        GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        If Trim(GV_SELECTED_EVENTID) = "" Then
            TreeView2.CollapseAll()
            'MsgBox("Please select event.")
            Exit Sub
        End If

        If TreeView2.SelectedNode Is Nothing Then
            TreeView2.CollapseAll()
            'MsgBox("Please select event.")
            Exit Sub
        Else

        End If

        Dim selectedparenteventid As String
        Dim somename2 As String
        Dim totalcount As String

        selectedparenteventid = TreeView2.SelectedNode.Name
        somename2 = TreeView2.SelectedNode.Nodes.Count

        'check to see if curreny selected row is parent row 'E'
        If (selectedparenteventid.Trim.Substring(0, 1) = "E") Then

        Else
            selectedparenteventid = TreeView2.SelectedNode.Parent.Name
        End If

        'Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        'Dim DAHistologyTemp As New SqlClient.SqlDataAdapter("SELECT Histology_msg, EVENT_ID, PT_Id1, Histo_ID , Status FROM Histology where STATUS <> 'D' and EVENT_ID = '" & selectedparenteventid & "'", CNnwind2)
        'Dim DSNWindTemp As DataSet
        'DSNWindTemp = New DataSet()
        'DAHistologyTemp.Fill(DSNWindTemp, "dtHistologyTemp")
        'totalcount = DSNWindTemp.Tables(0).Rows.Count

        'If (totalcount > 0) Then
        'MsgBox("Please add new event. There is alreadly an existing histology for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")

        'Exit Sub
        'End If

        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_HISTOLOGYID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            '   GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "S" Then GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name Else GV_SELECTED_HISTOLOGYID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If

        Me.displayPatientData(GV_SELECTED_EVENTID)
    End Sub

    Private Sub TreeView2_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView2.MouseClick
        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub

        End If

        'Added by cherwei to check for lock status and disallow adding new data if locked
        Dim vEventIDtemp As String
        vEventIDtemp = ""

        Try
            vEventIDtemp = TreeView2.SelectedNode.Name
            If vEventIDtemp.StartsWith("E") Then
            Else
                vEventIDtemp = TreeView2.SelectedNode.Parent.Name
            End If


            'If IsApprovedEvent(vEventIDtemp) = True Then
            'MsgBox("Please unlock event before adding new Histology for Event: " + vEventIDtemp)
            'Exit Sub
            'End If

            If TreeView2.Nodes.Count = 0 Then
                MsgBox("Please add new event.")
                Exit Sub
            End If

            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            If Trim(GV_SELECTED_EVENTID) = "" Then
                'MsgBox("Please select event.")
                Exit Sub
            End If

            If TreeView2.SelectedNode Is Nothing Then
                'MsgBox("Please select event.")
                Exit Sub
            Else

            End If

            Dim selectedparenteventid As String
            Dim somename2 As String
            Dim totalcount As String

            selectedparenteventid = TreeView2.SelectedNode.Name
            somename2 = TreeView2.SelectedNode.Nodes.Count

            'check to see if curreny selected row is parent row 'E'
            If (selectedparenteventid.Trim.Substring(0, 1) = "E") Then

            Else
                selectedparenteventid = TreeView2.SelectedNode.Parent.Name
            End If

            'Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
            'Dim DAHistologyTemp As New SqlClient.SqlDataAdapter("SELECT Histology_msg, EVENT_ID, PT_Id1, Histo_ID , Status FROM Histology where STATUS <> 'D' and EVENT_ID = '" & selectedparenteventid & "'", CNnwind2)
            'Dim DSNWindTemp As DataSet
            'DSNWindTemp = New DataSet()
            'DAHistologyTemp.Fill(DSNWindTemp, "dtHistologyTemp")
            'totalcount = DSNWindTemp.Tables(0).Rows.Count

            'If (totalcount > 0) Then
            'MsgBox("Please add new event. There is alreadly an existing histology for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")

            'Exit Sub
            'End If

            If TreeView2.SelectedNode.Level = 0 Then
                GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
                GV_SELECTED_HISTOLOGYID = ""
            End If

            If TreeView2.SelectedNode.Level = 1 Then
                '   GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name
                If TreeView2.SelectedNode.Name.Substring(0, 1) = "S" Then GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name Else GV_SELECTED_HISTOLOGYID = ""
                GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
            End If
            Me.displayPatientData(GV_SELECTED_EVENTID)
        Catch ex As Exception
            'MsgBox(ex.Source)
        End Try

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        'validation to check if there is no events, do not allow form to open
        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please create an event first.")
            Exit Sub
        End If

        'validation to check if histology is already created, if no histology present for current event, prompt to save histo 1st

        Dim SqlConnection2 As New SqlConnection()
        SqlConnection2 = New SqlConnection(GV_CONNETION)
        If SqlConnection2.State = ConnectionState.Closed Then SqlConnection2.Open()
        Dim sqlCmd2 = New SqlCommand("select top 1 histo_id,histoIDold from histology where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection2)
        Try
            Dim objReader As SqlDataReader = sqlCmd2.ExecuteReader
            Do While objReader.Read
                vHisto_ID = IIf(IsDBNull(objReader("histo_id")), "", objReader("histo_id"))
                vHistoIDold = "S" + IIf(IsDBNull(objReader("histoIDold")), "", objReader("histoIDold"))
            Loop

        Catch ex As Exception
            'MsgBox(ex.Source)
        End Try

        sqlCmd2.Cancel()
        SqlConnection2.Close()
        sqlCmd2 = Nothing
        SqlConnection2.Close()

        If (vHisto_ID = "") Then
            MsgBox("Please create an event or histology first.")
            Exit Sub
        End If

        'validation added by cherwei, if current event is locked, do not allow new neoadj treatments to be added
        If Approved() = True Then


            Dim SqlConnection1 As New SqlConnection()
            SqlConnection1 = New SqlConnection(GV_CONNETION)
            If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
            Dim sqlCmd = New SqlCommand("select Neoadj_id from NEOADJ where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection1)
            Try
                Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
                Do While objReader.Read
                    vNeoAdj_ID = IIf(IsDBNull(objReader("Neoadj_id")), "", objReader("Neoadj_id"))
                    GV_SELECTED_NEOADJID = vNeoAdj_ID
                Loop

            Catch ex As Exception
                'MsgBox(ex.Source)
            End Try

            sqlCmd.Cancel()
            SqlConnection1.Close()
            sqlCmd = Nothing
            SqlConnection1.Close()

            If LTrim(RTrim(vNeoAdj_ID)) = "" Then
                'MsgBox("Please unlock event before creating new neoadjuvant details")
                'Else

                'GV_SELECTED_HISTOLOGYID =
                FrmNeoadjuvant.ShowDialog()

            Else
                FrmNeoadjuvant.ShowDialog()
            End If

            'modified to check event table for lock status to determine final lock status
            Dim parentnode As TreeNode
            Dim DSNWind As DataSet
            Dim CNnwind As New SqlClient.SqlConnection(GV_CONNETION)
            'Dim DAEvent As New SqlClient.SqlDataAdapter("SELECT Event_msg, Event_ID,Status FROM Event where status <>'D' and pt_id1 = '" & GV_CUR_PATID & "'  order by date_tb " & GV_EVENT_SORT, CNnwind)
            Dim DAEvent As New SqlClient.SqlDataAdapter("SELECT Event_msg, Event_ID,Status FROM Event where status <>'D' and Event_ID = '" & GV_SELECTED_EVENTID & "'", CNnwind)

            DSNWind = New DataSet()
            CNnwind.Open()
            DSNWind.Clear()
            DAEvent.Fill(DSNWind, "dtEvent")

            CNnwind.Close()

            Dim i, n As Integer
            Dim parentrow As DataRow
            Dim ParentTable As DataTable
            ParentTable = DSNWind.Tables("dtEvent")


            Dim parentnodeStatuts As TreeNode
            For Each parentrow In ParentTable.Rows

                parentnode = New TreeNode(parentrow.Item(0))
                ' level 0 .. event id
                currentEventStatus = parentrow("Status")

                If currentEventStatus = "P" Then
                    FrmNeoadjuvant.btnSave.Enabled = False
                Else
                    FrmNeoadjuvant.btnSave.Enabled = True
                End If
            Next


        Else
            'if current event is locked and no neoadjuvant created, do not allow popup n exit
            Dim SqlConnection1 As New SqlConnection()
            SqlConnection1 = New SqlConnection(GV_CONNETION)
            If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
            Dim sqlCmd = New SqlCommand("select status from event where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection1)
            Try
                Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
                Do While objReader.Read
                    currentEventStatus = IIf(IsDBNull(objReader("status")), "", objReader("status"))
                Loop

            Catch ex As Exception
                'MsgBox(ex.Source)
            End Try

            'If (LTrim(RTrim(vNeoAdj_ID)) = "" And currentEventStatus = "P") Then
            'MsgBox("Please unlock before adding new neoadjuvant details.")
            'Exit Sub
            'Else
            FrmNeoadjuvant.ShowDialog()
            'End If

        End If
    End Sub
    Function Approved() As Boolean
        Dim vStatus As String = ""
        Dim vLockBy As String = ""
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()

        'modified by cherwei to use the old histology id if available
        'If (vHistoIDold.Trim() <> "S") Then
        'GV_SELECTED_HISTOLOGYID = vHistoIDold
        'Else
        GV_SELECTED_HISTOLOGYID = vHisto_ID
        'End If

        'Dim sqlCmd = New SqlCommand("select * from Histology where Histo_ID = '" & GV_SELECTED_HISTOLOGYID & "'", SqlConnection1)
        Dim sqlCmd = New SqlCommand("SELECT Event_msg, Event_ID,Status FROM Event where status <>'D' and pt_id1 = '" & GV_SELECTED_EVENTID & "'", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Do While objReader.Read
                vStatus = IIf(IsDBNull(objReader("Status")), "", objReader("Status"))
                vLockBy = IIf(IsDBNull(objReader("LockedBy")), "", objReader("LockedBy"))
            Loop

        Catch e As Exception
            'MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
        If vLockBy.Trim() <> "" Then
            Approved = True
            'btnSave.Enabled = False
            'BtnLock.Visible = False
        Else
            Approved = False
            'btnSave.Enabled = True
            'BtnLock.Visible = False
        End If
    End Function

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'validation to check if there is no events, do not allow form to open
        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please create an event first.")
            Exit Sub
        End If

        'validation to check if histology is already created, if no histology present for current event, prompt to save histo 1st
        Dim vHisto_ID As String = ""
        Dim SqlConnection2 As New SqlConnection()
        SqlConnection2 = New SqlConnection(GV_CONNETION)
        If SqlConnection2.State = ConnectionState.Closed Then SqlConnection2.Open()
        Dim sqlCmd2 = New SqlCommand("select histo_id from histology where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection2)
        Try
            Dim objReader As SqlDataReader = sqlCmd2.ExecuteReader
            Do While objReader.Read
                vHisto_ID = IIf(IsDBNull(objReader("histo_id")), "", objReader("histo_id"))
            Loop

        Catch ex As Exception
            'MsgBox(ex.Source)
        End Try

        sqlCmd2.Cancel()
        SqlConnection2.Close()
        sqlCmd2 = Nothing
        SqlConnection2.Close()

        If (vHisto_ID = "") Then
            MsgBox("Please create an event or histology first.")
            Exit Sub
        End If

        'added by cherwei for validation such that a new prior treatment form cannot be saved if current event is locked
        'validation added by cherwei, if current event is locked, do not allow new neoadj treatments to be added
        If Approved() = True Then

            Dim vNeoAdj_ID As String = ""
            Dim SqlConnection1 As New SqlConnection()
            SqlConnection1 = New SqlConnection(GV_CONNETION)
            If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
            Dim sqlCmd = New SqlCommand("select priortx_id from priortx where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection1)
            Try
                Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
                Do While objReader.Read
                    vNeoAdj_ID = IIf(IsDBNull(objReader("priortx_id")), "", objReader("priortx_id"))
                Loop

            Catch ex As Exception
                'MsgBox(ex.Source)
            End Try

            sqlCmd.Cancel()
            SqlConnection1.Close()
            sqlCmd = Nothing
            SqlConnection1.Close()

            If LTrim(RTrim(vNeoAdj_ID)) = "" Then
                MsgBox("Please unlock event before creating new prior treatment record")
            Else
                FrmRcdPriorTreatment.ShowDialog()
            End If


            'TreeView2.Nodes.TreeNode()


            'modified to check event table for lock status to determine final lock status
            Dim parentnode As TreeNode
            Dim DSNWind As DataSet
            Dim CNnwind As New SqlClient.SqlConnection(GV_CONNETION)
            'Dim DAEvent As New SqlClient.SqlDataAdapter("SELECT Event_msg, Event_ID,Status FROM Event where status <>'D' and pt_id1 = '" & GV_CUR_PATID & "'  order by date_tb " & GV_EVENT_SORT, CNnwind)
            Dim DAEvent As New SqlClient.SqlDataAdapter("SELECT Event_msg, Event_ID,Status FROM Event where status <>'D' and pt_id1 = '" & GV_SELECTED_EVENTID & "'", CNnwind)


            DSNWind = New DataSet()
            CNnwind.Open()
            DSNWind.Clear()
            DAEvent.Fill(DSNWind, "dtEvent")

            Dim i, n As Integer
            Dim parentrow As DataRow
            Dim ParentTable As DataTable
            ParentTable = DSNWind.Tables("dtEvent")

            For Each parentrow In ParentTable.Rows
                Dim currentEventStatus As String
                Dim parentnodeStatuts As TreeNode
                parentnode = New TreeNode(parentrow.Item(0))
                ' level 0 .. event id
                currentEventStatus = parentrow("Status")

                If currentEventStatus = "P" Then
                    FrmRcdPriorTreatment.btnSave.Enabled = False
                Else
                    FrmRcdPriorTreatment.btnSave.Enabled = True
                End If
            Next

        Else
            FrmRcdPriorTreatment.ShowDialog()
        End If

    End Sub


    Private Sub TreeView2_ParentChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView2.ParentChanged
        'TreeView2_MouseClick(sender, e)
    End Sub



    Private Sub TreeView2_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView2.AfterSelect
        If TreeView2.Nodes.Count = 0 Then
            'MsgBox("Please add new event.")
            Exit Sub
        End If

        'Added by cherwei to check for lock status and disallow adding new data if locked
        Dim vEventIDtemp As String
        vEventIDtemp = ""

        vEventIDtemp = TreeView2.SelectedNode.Name
        If vEventIDtemp.StartsWith("E") Then
        Else
            vEventIDtemp = TreeView2.SelectedNode.Parent.Name
        End If

        'If IsApprovedEvent(vEventIDtemp) = True Then
        'MsgBox("Please unlock event before adding new Histology for Event: " + vEventIDtemp)
        'Exit Sub
        'End If

        If TreeView2.Nodes.Count = 0 Then
            'MsgBox("Please add new event.")
            Exit Sub
        End If

        GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        If Trim(GV_SELECTED_EVENTID) = "" Then
            'MsgBox("Please select event.")
            Exit Sub
        End If

        If TreeView2.SelectedNode Is Nothing Then
            'MsgBox("Please select event.")
            Exit Sub
        Else

        End If

        Dim selectedparenteventid As String
        Dim somename2 As String
        Dim totalcount As String

        selectedparenteventid = TreeView2.SelectedNode.Name
        somename2 = TreeView2.SelectedNode.Nodes.Count

        'check to see if curreny selected row is parent row 'E'
        If (selectedparenteventid.Trim.Substring(0, 1) = "E") Then

        Else
            selectedparenteventid = TreeView2.SelectedNode.Parent.Name
        End If

        'Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        'Dim DAHistologyTemp As New SqlClient.SqlDataAdapter("SELECT Histology_msg, EVENT_ID, PT_Id1, Histo_ID , Status FROM Histology where STATUS <> 'D' and EVENT_ID = '" & selectedparenteventid & "'", CNnwind2)
        'Dim DSNWindTemp As DataSet
        'DSNWindTemp = New DataSet()
        'DAHistologyTemp.Fill(DSNWindTemp, "dtHistologyTemp")
        'totalcount = DSNWindTemp.Tables(0).Rows.Count

        'If (totalcount > 0) Then
        'MsgBox("Please add new event. There is alreadly an existing histology for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")

        'Exit Sub
        'End If

        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_HISTOLOGYID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            '   GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "S" Then GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name Else GV_SELECTED_HISTOLOGYID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If
        Me.displayPatientData(GV_SELECTED_EVENTID)
    End Sub

    Private Sub TreeView2_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TreeView2.Leave
        If TreeView2.Nodes.Count = 0 Then
            'MsgBox("Please add new event.")
            Exit Sub
        End If

        'Added by cherwei to check for lock status and disallow adding new data if locked
        Dim vEventIDtemp As String
        vEventIDtemp = ""

        Try
            vEventIDtemp = TreeView2.SelectedNode.Name
            If vEventIDtemp.StartsWith("E") Then
            Else
                vEventIDtemp = TreeView2.SelectedNode.Parent.Name
            End If

            'If IsApprovedEvent(vEventIDtemp) = True Then
            'MsgBox("Please unlock event before adding new Histology for Event: " + vEventIDtemp)
            'Exit Sub
            'End If
        Catch ex As Exception

        End Try


        If TreeView2.Nodes.Count = 0 Then
            'MsgBox("Please add new event.")
            Exit Sub
        End If

        Try
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            If Trim(GV_SELECTED_EVENTID) = "" Then
                'MsgBox("Please select event.")
                Exit Sub
            End If
        Catch ex As Exception
            Exit Sub
        End Try

        If TreeView2.SelectedNode Is Nothing Then
            'MsgBox("Please select event.")
            Exit Sub
        Else
        End If

        Dim selectedparenteventid As String
        Dim somename2 As String
        Dim totalcount As String

        selectedparenteventid = TreeView2.SelectedNode.Name
        somename2 = TreeView2.SelectedNode.Nodes.Count

        'check to see if curreny selected row is parent row 'E'
        If (selectedparenteventid.Trim.Substring(0, 1) = "E") Then

        Else
            selectedparenteventid = TreeView2.SelectedNode.Parent.Name
        End If

        'Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        'Dim DAHistologyTemp As New SqlClient.SqlDataAdapter("SELECT Histology_msg, EVENT_ID, PT_Id1, Histo_ID , Status FROM Histology where STATUS <> 'D' and EVENT_ID = '" & selectedparenteventid & "'", CNnwind2)
        'Dim DSNWindTemp As DataSet
        'DSNWindTemp = New DataSet()
        'DAHistologyTemp.Fill(DSNWindTemp, "dtHistologyTemp")
        'totalcount = DSNWindTemp.Tables(0).Rows.Count

        'If (totalcount > 0) Then
        'MsgBox("Please add new event. There is alreadly an existing histology for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")

        'Exit Sub
        'End If

        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_HISTOLOGYID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            '   GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "S" Then GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name Else GV_SELECTED_HISTOLOGYID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If
        Me.displayPatientData(GV_SELECTED_EVENTID)
    End Sub

    Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.Click

    End Sub


    Private Sub SavePatientHistory()
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertHistory", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@History_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@FamilyHistory", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Menstrual", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

        Dim currentSelectedEvent As String = GV_SELECTED_EVENTID
        Dim count As Integer = DSNHistory.Tables("dtHistory").Rows.Count
        If (count > 0) Then
            GV_SELECTED_HISTORYID = DSNHistory.Tables("dtHistory").Rows(0).Item("History_ID")
        End If

        If Trim(GV_SELECTED_HISTORYID).IndexOf("H") = -1 Then
            gv_isedit = False
        Else
            gv_isedit = True
        End If

        If GV_ISEDIT = True Then
            myCommand.Parameters("@History_ID").Value = GV_SELECTED_HISTORYID
        Else
            myCommand.Parameters("@History_ID").Value = "0"
        End If
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
        myCommand.Parameters("@FamilyHistory").Value = Trim(cbxHistory.Text)
        myCommand.Parameters("@Menstrual").Value = Trim(cbxStatus.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER

        myCommand.ExecuteNonQuery()

        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing
    End Sub
    Private Sub SavePatientEvent()
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertEvent", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@date_tb", SqlDbType.DateTime)
        myCommand.Parameters.Add("@date_cn", SqlDbType.DateTime)
        myCommand.Parameters.Add("@doc_inc", SqlDbType.VarChar)
        myCommand.Parameters.Add("@case_type", SqlDbType.VarChar)
        myCommand.Parameters.Add("@brst_screen", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Metasyn_Status", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Metasynchronous", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_id_old", SqlDbType.VarChar)
        Dim currentSelectedEvent As String = GV_SELECTED_EVENTID
        Dim count As Integer = DSNEvent.Tables("dtEvent").Rows.Count
        If (count > 0) Then
            GV_SELECTED_EVENTID = DSNEvent.Tables("dtEvent").Rows(0).Item("Event_ID")
        End If

        If Trim(GV_SELECTED_EVENTID).IndexOf("E") = -1 Then
            gv_isedit = False
        Else
            gv_isedit = True
        End If

        If gv_isedit = True Then
            myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
        Else
            myCommand.Parameters("@Event_ID").Value = "0"
        End If
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@date_tb").Value = FormatDateTime(DOB.Value, DateFormat.ShortDate)
        myCommand.Parameters("@date_cn").Value = FormatDateTime(DateTimePicker1.Value, DateFormat.ShortDate)
        myCommand.Parameters("@doc_inc").Value = Trim(cbxDoctor.Text)
        myCommand.Parameters("@case_type").Value = Trim(cbxCaseType.Text)
        myCommand.Parameters("@brst_screen").Value = Trim(cbxLaterality.Text)
        myCommand.Parameters("@Metasyn_Status").Value = Trim(CboxMeta.Text)
        myCommand.Parameters("@Metasynchronous").Value = Trim(CboxMetasEvent.SelectedValue)
        myCommand.Parameters("@EnteredBy").Value = GV_USER
        myCommand.Parameters("@Event_id_old").Value = ""
        myCommand.ExecuteNonQuery()

        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing

        'FrmDiagnosis.TreeView2.CollapseAll()
    End Sub

    Private Sub SaveInvestigation()
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertInvestigation", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@Inv_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@CXR", SqlDbType.VarChar)
        myCommand.Parameters.Add("@CT", SqlDbType.VarChar)
        myCommand.Parameters.Add("@BoneScan", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Notes", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

        Dim currentSelectedEvent As String = GV_SELECTED_EVENTID
        Dim count As Integer = DSNInvestigation.Tables("dtInvestigation").Rows.Count
        If (count > 0) Then
            GV_SELECTED_INVESTID = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("Inv_id")
        End If

        If Trim(GV_SELECTED_INVESTID).IndexOf("I") = -1 Then
            gv_isedit = False
        Else
            gv_isedit = True
        End If

        If gv_isedit = True Then
            myCommand.Parameters("@Inv_ID").Value = GV_SELECTED_INVESTID
        Else
            myCommand.Parameters("@Inv_ID").Value = "0"
        End If
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
        myCommand.Parameters("@CXR").Value = Trim(cbxCXR.SelectedValue)
        myCommand.Parameters("@CT").Value = Trim(cbxCT.SelectedValue)
        myCommand.Parameters("@BoneScan").Value = Trim(cbxBone.SelectedValue)
        myCommand.Parameters("@Notes").Value = Trim(RichTextNotes.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER
        myCommand.ExecuteNonQuery()

        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing


    End Sub

    Private Sub SaveHistology()

        Dim physicalnotes As String
        physicalnotes = txtPhysicalNotes.Text


        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        Try
            SqlConn = New SqlConnection(GV_CONNETION)
            myCommand = New SqlCommand("spInsertHistology", SqlConn)
            myCommand.CommandType = CommandType.StoredProcedure
            SqlConn.Open()

            myCommand.Parameters.Add("@Histo_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@clin_tum_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Ext_cw", SqlDbType.VarChar)
            myCommand.Parameters.Add("@clin_ax_ln", SqlDbType.VarChar)
            myCommand.Parameters.Add("@biopsy_Type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@date_biopsy", SqlDbType.DateTime)
            myCommand.Parameters.Add("@histo_Dx", SqlDbType.VarChar)
            myCommand.Parameters.Add("@date_pri_surg", SqlDbType.DateTime)
            myCommand.Parameters.Add("@surg_type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@reconstruction", SqlDbType.VarChar)
            myCommand.Parameters.Add("@chk_Neoadj", SqlDbType.Bit)
            myCommand.Parameters.Add("@chk_Local", SqlDbType.Bit)
            myCommand.Parameters.Add("@chk_Systemic", SqlDbType.Bit)
            myCommand.Parameters.Add("@add_physurg_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@other_histo_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_tum_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_grade", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ass_dcis", SqlDbType.VarChar)
            myCommand.Parameters.Add("@lymphovas_inv", SqlDbType.VarChar)
            myCommand.Parameters.Add("@marg_inv_ca", SqlDbType.VarChar)
            myCommand.Parameters.Add("@marg_dcis", SqlDbType.VarChar)
            myCommand.Parameters.Add("@closest_marg", SqlDbType.VarChar)
            myCommand.Parameters.Add("@closest_marg_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@deep_marg_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@SLN_1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@SLN_2", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ax_ln_pos", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ax_ln_fd", SqlDbType.VarChar)
            myCommand.Parameters.Add("@er_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@pr_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@c_erbb2_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@t_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@n_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@m_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

            'myCommand.Parameters.Add("@side", SqlDbType.VarChar)

            Dim currentSelectedEvent As String = GV_SELECTED_EVENTID
            Dim count As Integer = Me.DSNHistology.Tables("dtHistology").Rows.Count
            If (count > 0) Then
                GV_SELECTED_HISTOLOGYID = DSNHistology.Tables("dtHistology").Rows(0).Item("histo_id")
            End If

            If Trim(GV_SELECTED_HISTOLOGYID).IndexOf("S") = -1 Then
                gv_isedit = False
            Else
                gv_isedit = True
            End If

            If gv_isedit = True Then
                myCommand.Parameters("@Histo_ID").Value = GV_SELECTED_HISTOLOGYID
            Else
                myCommand.Parameters("@Histo_ID").Value = "0"
            End If
            myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
            myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID

            'If Not IsNumeric(txtTumourSize.Text) Then
            'Me.ErrorProvider1.SetError(Me.txtTumourSize, "Please Enter numeric values for tumor size")
            'Throw New Exception("Please enter a numeric value")
            'Else
            'myCommand.Parameters("@clin_tum_size").Value = Trim(txtTumourSize.Text)
            'End If
            myCommand.Parameters("@clin_tum_size").Value = Trim(txtTumourSize.Text)
            myCommand.Parameters("@Ext_cw").Value = Trim(cbxExtChestWall.Text)
            myCommand.Parameters("@clin_ax_ln").Value = Trim(cbxClinAxillaryLN.Text)
            myCommand.Parameters("@biopsy_Type").Value = Trim(cbxTypeBiopsy.Text)
            myCommand.Parameters("@date_biopsy").Value = dtDateBiopsy.Value
            myCommand.Parameters("@histo_Dx").Value = Trim(cbxHistoDx.Text)
            myCommand.Parameters("@date_pri_surg").Value = DtPrisurg.Value
            myCommand.Parameters("@surg_type").Value = Trim(cbxTypeSurg.Text)
            myCommand.Parameters("@reconstruction").Value = Trim(cbxReconstruction.Text)
            myCommand.Parameters("@chk_Neoadj").Value = cboxNeoadjuvant.Checked
            myCommand.Parameters("@chk_Local").Value = cboxLocalRec.Checked
            myCommand.Parameters("@chk_Systemic").Value = cboxSystemic.Checked
            myCommand.Parameters("@add_physurg_notes").Value = Trim(txtPhysicalNotes.Text)
            myCommand.Parameters("@other_histo_notes").Value = Trim(txtHistoNotes.Text)
            myCommand.Parameters("@histo_tum_size").Value = Trim(txtHisto_TumourSize.Text)
            myCommand.Parameters("@histo_type").Value = Trim(cbxHistoType.Text)
            myCommand.Parameters("@histo_grade").Value = Trim(cbxHistoGrade.Text)
            myCommand.Parameters("@ass_dcis").Value = Trim(cbxDCIS.Text)
            myCommand.Parameters("@lymphovas_inv").Value = Trim(cbxLymhovascular.Text)
            myCommand.Parameters("@marg_inv_ca").Value = Trim(cbxMargin_invasive.Text)
            myCommand.Parameters("@marg_dcis").Value = Trim(cboxMarginDCIS.Text)
            myCommand.Parameters("@closest_marg").Value = Trim(cbxradialMargin.Text)
            myCommand.Parameters("@closest_marg_size").Value = Trim(txtRadialMargin.Text)
            myCommand.Parameters("@deep_marg_size").Value = Trim(txtDeepMargin.Text)
            myCommand.Parameters("@SLN_1").Value = Trim(cbxSentinel_LN.Text)
            myCommand.Parameters("@SLN_2").Value = Trim(cbxSentinelLNPolarity.Text)
            myCommand.Parameters("@ax_ln_pos").Value = Trim(txtTotal_Ax_LN_Postive.Text)
            myCommand.Parameters("@ax_ln_fd").Value = Trim(txtTotal_Ax_LN_Found.Text)
            myCommand.Parameters("@er_status").Value = Trim(cbxER_Status.Text)
            myCommand.Parameters("@pr_status").Value = Trim(cbxPR_Status.Text)
            myCommand.Parameters("@c_erbb2_status").Value = Trim(cbxErbB2.Text)
            myCommand.Parameters("@t_stage_6").Value = Trim(cbxcT_Status.Text)
            myCommand.Parameters("@n_stage_6").Value = Trim(cbxN_Status.Text)
            myCommand.Parameters("@m_stage_6").Value = Trim(cbxM_Status.Text)
            myCommand.Parameters("@EnteredBy").Value = GV_USER

            'myCommand.Parameters("@side").Value = Trim(cbxSide.Text)

            myCommand.ExecuteNonQuery()

            myCommand.Cancel()
            SqlConn.Close()
            myCommand = Nothing
            SqlConn = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

    End Sub

    Private Sub SaveTxRecommend()
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertTxRecommendation", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@recom_id", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@recommendation", SqlDbType.VarChar)
        myCommand.Parameters.Add("@chemotherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@hormonaltherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@radiotherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@surgery", SqlDbType.Bit)
        myCommand.Parameters.Add("@immunotherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@recommend_notes", SqlDbType.VarChar)
        myCommand.Parameters.Add("@form_complete", SqlDbType.Bit)
        myCommand.Parameters.Add("@update_notes", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)


        Dim currentSelectedEvent As String = GV_SELECTED_EVENTID
        Dim count As Integer = DSNTxRecommendation.Tables("dtTxRecommendation").Rows.Count
        If (count > 0) Then
            GV_SELECTED_TXID = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recom_id")
        End If

        If Trim(GV_SELECTED_TXID).IndexOf("T") = -1 Then
            gv_isedit = False
        Else
            gv_isedit = True
        End If

        If gv_isedit = True Then
            myCommand.Parameters("@recom_id").Value = GV_SELECTED_TXID
        Else
            myCommand.Parameters("@recom_id").Value = "0"
        End If
        myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@recommendation").Value = Trim(cbxBTBRecommend.Text)
        myCommand.Parameters("@chemotherapy").Value = cboxChemo.Checked
        myCommand.Parameters("@hormonaltherapy").Value = cboxHormonal.Checked
        myCommand.Parameters("@radiotherapy").Value = cboxRadio.Checked
        myCommand.Parameters("@surgery").Value = cboxSurgery.Checked
        myCommand.Parameters("@immunotherapy").Value = cboxTargerted.Checked
        myCommand.Parameters("@recommend_notes").Value = Trim(txtComments.Text)
        myCommand.Parameters("@form_complete").Value = cboxComplete.Checked
        myCommand.Parameters("@update_notes").Value = Trim(txtNotes.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER
        myCommand.ExecuteNonQuery()

        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing
    End Sub

    Private Sub btnInvest2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInvest2.Click
        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        'Added by cherwei to check for lock status and disallow adding new data if locked
        Dim vEventIDtemp As String
        vEventIDtemp = ""
        vEventIDtemp = TreeView2.SelectedNode.Name
        If vEventIDtemp.StartsWith("E") Then
        Else
            vEventIDtemp = TreeView2.SelectedNode.Parent.Name
        End If

        If IsApprovedEvent(vEventIDtemp) = True Then
            MsgBox("Please unlock event before adding new investigation for Event: " + vEventIDtemp)
            Exit Sub
        End If

        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        If Trim(GV_SELECTED_EVENTID) = "" Then
            MsgBox("Please select event.")
            Exit Sub
        End If

        If TreeView2.SelectedNode Is Nothing Then
            MsgBox("Please select event.")
            Exit Sub
        Else
        End If
        'Dim oFrmInvestigation As New FrmInvestigation()
        'oFrmInvestigation.Show()
        Dim selectedparenteventid As String
        Dim somename2 As String
        Dim totalcount As String


        selectedparenteventid = TreeView2.SelectedNode.Name
        somename2 = TreeView2.SelectedNode.Nodes.Count

        'check to see if the current selected row is Parent row 'E'
        If (selectedparenteventid.Trim.Substring(0, 1) = "E") Then
            'does not need further check as selected row is alreadly the parent node
        Else
            selectedparenteventid = TreeView2.SelectedNode.Parent.Name
        End If

        Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAInvestigationTemp As New SqlClient.SqlDataAdapter("SELECT INV_MSG, EVENT_ID, PT_Id1, INV_ID, Status FROM INVESTIGATION where STATUS <> 'D' and EVENT_ID = '" & selectedparenteventid & "'", CNnwind2)
        Dim DSNWindTemp As DataSet
        DSNWindTemp = New DataSet()
        DAInvestigationTemp.Fill(DSNWindTemp, "dtInvestigationTemp")
        totalcount = DSNWindTemp.Tables(0).Rows.Count

        If (totalcount > 0) Then
            MsgBox("Please add new event. There is alreadly an existing investigation for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")
            Exit Sub
        End If

        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_INVESTID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "I" Then GV_SELECTED_INVESTID = TreeView2.SelectedNode.Name Else GV_SELECTED_INVESTID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If

        FrmInvestigation.Close()
        FrmInvestigation.Show()
        FrmInvestigation.Focus()
        'FrmInvestigation.Button1_Click(sender, e)

        'btnInvest_Click(sender, e)
    End Sub

    Private Sub btnMedHis2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMedHis2.Click
        'Added by cherwei to check for lock status and disallow adding new data if locked
        Dim vEventIDtemp As String
        vEventIDtemp = ""

        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event")
            Exit Sub
        End If

        vEventIDtemp = TreeView2.SelectedNode.Name
        If vEventIDtemp.StartsWith("E") Then
        Else
            vEventIDtemp = TreeView2.SelectedNode.Parent.Name
        End If

        If IsApprovedEvent(vEventIDtemp) = True Then
            MsgBox("Please unlock event before adding new medical history for Event: " + vEventIDtemp)
            Exit Sub
        End If

        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        If Trim(GV_SELECTED_EVENTID) = "" Then
            MsgBox("Please select event.")
            Exit Sub
        End If

        Dim selectedparenteventid As String
        Dim somename2 As String
        Dim totalcount As String


        selectedparenteventid = TreeView2.SelectedNode.Name
        somename2 = TreeView2.SelectedNode.Nodes.Count

        'check to see if the current selected row is Parent row 'E'
        If (selectedparenteventid.Trim.Substring(0, 1) = "E") Then
            'does not need further check as selected row is alreadly the parent node
        Else
            selectedparenteventid = TreeView2.SelectedNode.Parent.Name
        End If


        'updated by cherwei on 14 May 2009 to include records with 'A' and 'P' status 

        Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAHistoryTemp As New SqlClient.SqlDataAdapter("SELECT HISTORY_MSG, EVENT_ID, PT_Id1, HISTORY_ID, Status FROM HISTORY where STATUS <> 'D' and EVENT_ID = '" & selectedparenteventid & "'", CNnwind2)
        Dim DSNWindTemp As DataSet
        DSNWindTemp = New DataSet()
        DAHistoryTemp.Fill(DSNWindTemp, "dtHistoryTemp")
        totalcount = DSNWindTemp.Tables(0).Rows.Count

        If (totalcount > 0) Then
            MsgBox("Please add new event. There is alreadly an existing medical history for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")
            Exit Sub
        End If



        'If TreeView2.SelectedNode Is Nothing Then
        'MsgBox("Please select event.")
        'Exit Sub
        'Else

        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_HISTORYID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "H" Then GV_SELECTED_HISTORYID = TreeView2.SelectedNode.Name Else GV_SELECTED_HISTORYID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If

        FrmHistory.Close()
        FrmHistory.Show()
        FrmHistory.Focus()
        'FrmHistory.btnAdd_Click(sender, e)
        'btnMedHis_Click(sender, e)
    End Sub

    Private Sub btnHisology2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHisology2.Click
        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        'Added by cherwei to check for lock status and disallow adding new data if locked
        Dim vEventIDtemp As String
        vEventIDtemp = ""

        Try
            vEventIDtemp = TreeView2.SelectedNode.Name
            If vEventIDtemp.StartsWith("E") Then
            Else
                vEventIDtemp = TreeView2.SelectedNode.Parent.Name
            End If
        Catch ex As Exception
            Console.WriteLine(ex.StackTrace)

        End Try
        

        'If IsApprovedEvent(vEventIDtemp) = True Then
        'MsgBox("Please unlock event before adding new Histology for Event: " + vEventIDtemp)
        'Exit Sub
        'End If

        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        If Trim(GV_SELECTED_EVENTID) = "" Then
            MsgBox("Please select event.")
            Exit Sub
        End If

        If TreeView2.SelectedNode Is Nothing Then
            MsgBox("Please select event.")
            Exit Sub
        Else

        End If

        Dim selectedparenteventid As String
        Dim somename2 As String
        Dim totalcount As String

        selectedparenteventid = TreeView2.SelectedNode.Name
        somename2 = TreeView2.SelectedNode.Nodes.Count

        'check to see if curreny selected row is parent row 'E'
        If (selectedparenteventid.Trim.Substring(0, 1) = "E") Then

        Else
            selectedparenteventid = TreeView2.SelectedNode.Parent.Name
        End If

        Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAHistologyTemp As New SqlClient.SqlDataAdapter("SELECT Histology_msg, EVENT_ID, PT_Id1, Histo_ID , Status FROM Histology where STATUS <> 'D' and EVENT_ID = '" & selectedparenteventid & "'", CNnwind2)
        Dim DSNWindTemp As DataSet
        DSNWindTemp = New DataSet()
        DAHistologyTemp.Fill(DSNWindTemp, "dtHistologyTemp")
        totalcount = DSNWindTemp.Tables(0).Rows.Count

        If (totalcount > 0) Then
            MsgBox("Please add new event. There is alreadly an existing histology for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")

            Exit Sub
        End If

        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_HISTOLOGYID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            '   GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "S" Then GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name Else GV_SELECTED_HISTOLOGYID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If

        FrmHistology.Close()
        FrmHistology.Show()
        FrmHistology.Focus()
        'FrmHistology.BtnAdd_Click(sender, e)
        'btnHisology_Click(sender, e)
    End Sub
    Private Sub enableAllFields()
        DOB.Enabled = True
        DateTimePicker1.Enabled = True
        cbxDoctor.Enabled = True
        cbxCaseType.Enabled = True
        cbxLaterality.Enabled = True
        CboxMeta.Enabled = True
        CboxMetasEvent.Enabled = True

        cbxCXR.Enabled = True
        cbxCT.Enabled = True
        cbxBone.Enabled = True
        RichTextNotes.Enabled = True
        cbxHistory.Enabled = True
        cbxStatus.Enabled = True
        txtTumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_tum_size")
        cbxExtChestWall.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("Ext_cw")
        cbxClinAxillaryLN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_ax_ln")
        cbxTypeBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("biopsy_Type")
        dtDateBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_biopsy")
        cbxHistoDx.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_Dx")
        DtPrisurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_pri_surg")
        cbxTypeSurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("surg_type")
        cbxReconstruction.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("reconstruction")
        cboxNeoadjuvant.Checked = True 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Neoadj")
        cboxLocalRec.Checked = True 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Local")
        cboxSystemic.Checked = True 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Systemic")
        txtPhysicalNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("add_physurg_notes")
        txtHistoNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("other_histo_notes")
        txtHisto_TumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_tum_size")
        cbxHistoType.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_type")
        cbxHistoGrade.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_grade")
        cbxDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ass_dcis")
        cbxLymhovascular.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("lymphovas_inv")
        cbxMargin_invasive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_inv_ca")
        cboxMarginDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_dcis")
        cbxradialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg")
        txtRadialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg_size")
        txtDeepMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("deep_marg_size")
        cbxSentinel_LN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("SLN_1")
        txtTotal_Ax_LN_Postive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_pos")
        txtTotal_Ax_LN_Found.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))
        cbxER_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("er_status")
        cbxPR_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("pr_status")
        cbxErbB2.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("c_erbb2_status")
        cbxcT_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("t_stage_6")
        cbxN_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("n_stage_6")
        cbxM_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("m_stage_6")

        txtTumourSize.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
        cbxExtChestWall.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
        cbxClinAxillaryLN.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
        cbxTypeBiopsy.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
        dtDateBiopsy.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
        cbxHistoDx.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
        DtPrisurg.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
        cbxTypeSurg.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
        cbxReconstruction.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
        cboxNeoadjuvant.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
        cboxLocalRec.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
        cboxSystemic.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
        txtPhysicalNotes.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
        txtHistoNotes.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
        txtHisto_TumourSize.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
        cbxHistoType.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
        cbxHistoGrade.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
        cbxDCIS.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
        cbxLymhovascular.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
        cbxMargin_invasive.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
        cboxMarginDCIS.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
        cbxradialMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
        txtRadialMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
        txtDeepMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
        cbxSentinel_LN.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
        txtTotal_Ax_LN_Postive.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
        txtTotal_Ax_LN_Found.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

        'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
        cbxER_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
        cbxPR_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
        cbxErbB2.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
        cbxcT_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
        cbxN_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
        cbxM_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")

        cbxBTBRecommend.Text = ""
        cboxChemo.Checked = True  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
        cboxHormonal.Checked = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
        cboxRadio.Checked = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
        cboxSurgery.Checked = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
        cboxTargerted.Checked = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
        cboxComplete.Checked = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
        txtComments.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
        txtNotes.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("update_notes")

        cbxBTBRecommend.Enabled = True
        cboxChemo.Enabled = True  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
        cboxHormonal.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
        cboxRadio.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
        cboxSurgery.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
        cboxTargerted.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
        cboxComplete.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
        txtComments.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
        txtNotes.Enabled = True
    End Sub

    Private Sub lockAllFields()
        cbxHistoType.Enabled = False


        DOB.Enabled = False
        DateTimePicker1.Enabled = False
        cbxDoctor.Enabled = False
        cbxCaseType.Enabled = False
        cbxLaterality.Enabled = False
        CboxMeta.Enabled = False
        CboxMetasEvent.Enabled = False

        cbxCXR.Enabled = False
        cbxCT.Enabled = False
        cbxBone.Enabled = False
        RichTextNotes.Enabled = False
        cbxHistory.Enabled = False
        cbxStatus.Enabled = False

        cboxNeoadjuvant.Checked = False
        cboxLocalRec.Checked = False
        cboxSystemic.Checked = False

        txtTumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
        cbxExtChestWall.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
        cbxClinAxillaryLN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
        cbxTypeBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
        dtDateBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
        cbxHistoDx.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
        DtPrisurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
        cbxTypeSurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
        cbxReconstruction.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
        cboxNeoadjuvant.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
        cboxLocalRec.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
        cboxSystemic.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
        txtPhysicalNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
        txtHistoNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
        txtHisto_TumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
        cbxHistoType.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
        cbxHistoGrade.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
        cbxDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
        cbxLymhovascular.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
        cbxMargin_invasive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
        cboxMarginDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
        cbxradialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
        txtRadialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
        txtDeepMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
        cbxSentinel_LN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
        txtTotal_Ax_LN_Postive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
        txtTotal_Ax_LN_Found.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

        'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
        cbxER_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
        cbxPR_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
        cbxErbB2.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
        cbxcT_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
        cbxN_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
        cbxM_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")


        cboxChemo.Checked = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
        cboxHormonal.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
        cboxRadio.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
        cboxSurgery.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
        cboxTargerted.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
        cboxComplete.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")

        cbxBTBRecommend.Enabled = False
        cboxChemo.Enabled = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
        cboxHormonal.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
        cboxRadio.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
        cboxSurgery.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
        cboxTargerted.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
        cboxComplete.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
        txtComments.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
        txtNotes.Enabled = False
    End Sub

    Private Sub disableAllFields()
        DOB.Enabled = False
        DateTimePicker1.Enabled = False
        cbxDoctor.Enabled = False
        cbxCaseType.Enabled = False
        cbxLaterality.Enabled = False
        CboxMeta.Enabled = False
        CboxMetasEvent.Enabled = False

        cbxCXR.Enabled = False
        cbxCT.Enabled = False
        cbxBone.Enabled = False
        RichTextNotes.Enabled = False
        cbxHistory.Enabled = False
        cbxStatus.Enabled = False
        txtTumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_tum_size")
        cbxExtChestWall.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("Ext_cw")
        cbxClinAxillaryLN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_ax_ln")
        cbxTypeBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("biopsy_Type")
        dtDateBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_biopsy")
        cbxHistoDx.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_Dx")
        DtPrisurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_pri_surg")
        cbxTypeSurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("surg_type")
        cbxReconstruction.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("reconstruction")
        cboxNeoadjuvant.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Neoadj")
        cboxLocalRec.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Local")
        cboxSystemic.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Systemic")
        txtPhysicalNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("add_physurg_notes")
        txtHistoNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("other_histo_notes")
        txtHisto_TumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_tum_size")
        cbxHistoType.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_type")
        cbxHistoGrade.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_grade")
        cbxDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ass_dcis")
        cbxLymhovascular.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("lymphovas_inv")
        cbxMargin_invasive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_inv_ca")
        cboxMarginDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_dcis")
        cbxradialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg")
        txtRadialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg_size")
        txtDeepMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("deep_marg_size")
        cbxSentinel_LN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("SLN_1")
        txtTotal_Ax_LN_Postive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_pos")
        txtTotal_Ax_LN_Found.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))
        cbxER_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("er_status")
        cbxPR_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("pr_status")
        cbxErbB2.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("c_erbb2_status")
        cbxcT_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("t_stage_6")
        cbxN_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("n_stage_6")
        cbxM_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("m_stage_6")

        txtTumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
        cbxExtChestWall.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
        cbxClinAxillaryLN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
        cbxTypeBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
        dtDateBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
        cbxHistoDx.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
        DtPrisurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
        cbxTypeSurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
        cbxReconstruction.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
        cboxNeoadjuvant.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
        cboxLocalRec.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
        cboxSystemic.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
        txtPhysicalNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
        txtHistoNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
        txtHisto_TumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
        cbxHistoType.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
        cbxHistoGrade.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
        cbxDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
        cbxLymhovascular.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
        cbxMargin_invasive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
        cboxMarginDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
        cbxradialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
        txtRadialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
        txtDeepMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
        cbxSentinel_LN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
        txtTotal_Ax_LN_Postive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
        txtTotal_Ax_LN_Found.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

        'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
        cbxER_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
        cbxPR_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
        cbxErbB2.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
        cbxcT_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
        cbxN_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
        cbxM_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")

        cbxBTBRecommend.Text = ""
        cboxChemo.Checked = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
        cboxHormonal.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
        cboxRadio.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
        cboxSurgery.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
        cboxTargerted.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
        cboxComplete.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
        txtComments.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
        txtNotes.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("update_notes")

        cbxBTBRecommend.Enabled = False
        cboxChemo.Enabled = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
        cboxHormonal.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
        cboxRadio.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
        cboxSurgery.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
        cboxTargerted.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
        cboxComplete.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
        txtComments.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
        txtNotes.Enabled = False
    End Sub


    Private Sub btnTxRec2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTxRec2.Click
        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        'Added by cherwei to check for lock status and disallow adding new data if locked
        Dim vEventIDtemp As String
        vEventIDtemp = ""

        vEventIDtemp = TreeView2.SelectedNode.Name
        If vEventIDtemp.StartsWith("E") Then
        Else
            vEventIDtemp = TreeView2.SelectedNode.Parent.Name
        End If

        If IsApprovedEvent(vEventIDtemp) = True Then
            MsgBox("Please unlock event before adding new Tx Recommendation for Event: " + vEventIDtemp)
            Exit Sub
        End If

        If TreeView2.Nodes.Count = 0 Then
            MsgBox("Please add new event.")
            Exit Sub
        End If

        GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
        If Trim(GV_SELECTED_EVENTID) = "" Then
            MsgBox("Please select event.")
            Exit Sub
        End If

        If TreeView2.SelectedNode Is Nothing Then
            MsgBox("Please select event.")
            Exit Sub
        Else

        End If


        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_TXID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "I" Then GV_SELECTED_TXID = TreeView2.SelectedNode.Name Else GV_SELECTED_TXID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If



        'Dim oFrmHistology As New FrmHistology()
        'oFrmHistology.Show()

        Dim selectedparenteventid As String
        Dim somename2 As String
        Dim totalcount As String


        selectedparenteventid = TreeView2.SelectedNode.Name
        somename2 = TreeView2.SelectedNode.Nodes.Count

        'check to see if the current selected row is Parent row 'E'
        If (selectedparenteventid.Trim.Substring(0, 1) = "E") Then
            'does not need further check as selected row is alreadly the parent node
        Else
            selectedparenteventid = TreeView2.SelectedNode.Parent.Name
        End If

        Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DATxRecommendationTemp As New SqlClient.SqlDataAdapter("SELECT Tx_msg, EVENT_ID, PT_Id1, recom_id , Status FROM recom where  status <>'D' and EVENT_ID = '" & selectedparenteventid & "'", CNnwind2)
        Dim DSNWindTemp As DataSet
        DSNWindTemp = New DataSet()
        DATxRecommendationTemp.Fill(DSNWindTemp, "dtTxRecommendationTemp")
        totalcount = DSNWindTemp.Tables(0).Rows.Count

        If (totalcount > 0) Then
            MsgBox("Please add new event. There is alreadly an existing TxRecommendation for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")
            Exit Sub
        End If

        If TreeView2.SelectedNode.Level = 0 Then
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Name
            GV_SELECTED_TXID = ""
        End If

        If TreeView2.SelectedNode.Level = 1 Then
            '   GV_SELECTED_HISTOLOGYID = TreeView2.SelectedNode.Name
            If TreeView2.SelectedNode.Name.Substring(0, 1) = "T" Then GV_SELECTED_TXID = TreeView2.SelectedNode.Name Else GV_SELECTED_TXID = ""
            GV_SELECTED_EVENTID = TreeView2.SelectedNode.Parent.Name()
        End If

        FrmTxRecommendation.Close()
        FrmTxRecommendation.Show()
        FrmTxRecommendation.Focus()
        'FrmTxRecommendation.btnAdd_Click(sender, e)
        'btnTxRec_Click(sender, e)
    End Sub

    Private Sub btnInvSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInvSave.Click
        If treeviewhasrows() = True Then
            If (GV_SELECTED_INVESTID <> "") Or (GV_SELECTED_INVESTID = "Nothing") Then

                Dim N As TreeNode
                N = TreeView2.SelectedNode
                currentselectedtab = TabControl1.SelectedTab.ToString()

                Me.SaveInvestigation()
                'btnRefresh_Click(sender, e)
                TreeView2.CollapseAll()

                TreeView2.SelectedNode = N 'GV_SELECTED_EVENTID
                TreeView2.Focus()

            End If
        Else
            MsgBox("There are no events selected/created. Please create an event first by clicking add new event button.")
        End If
    End Sub


    Private Sub btnTxRecSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTxRecSave.Click
        If treeviewhasrows() = True Then
            If (GV_SELECTED_TXID <> "") Then
                Dim N As TreeNode
                N = TreeView2.SelectedNode

                currentselectedtab = TabControl1.SelectedTab.ToString()

                Me.SaveTxRecommend()
                'btnRefresh_Click(sender, e)
                TreeView2.CollapseAll()

                TreeView2.SelectedNode = N 'GV_SELECTED_EVENTID
                TreeView2.Focus()
            End If
        Else
            MsgBox("There are no events selected. Please create an event first.")
        End If

    End Sub

    Private Sub btnHistologySave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHistologySave.Click
        If treeviewhasrows() = True Then
            If (GV_SELECTED_HISTOLOGYID <> "") Then
                Dim N As TreeNode
                N = TreeView2.SelectedNode

                currentselectedtab = TabControl1.SelectedTab.ToString()

                Me.SaveHistology()
                'btnRefresh_Click(sender, e)
                TreeView2.CollapseAll()

                TreeView2.SelectedNode = N 'GV_SELECTED_EVENTID
                TreeView2.Focus()
            End If
        Else
            MsgBox("There are no events selected. Please create an event first.")
        End If

    End Sub

    Private Sub btnHistorySave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHistorySave.Click
        If treeviewhasrows() = True Then
            If (GV_SELECTED_HISTORYID <> "") Then
                Dim N As TreeNode
                N = TreeView2.SelectedNode

                currentselectedtab = TabControl1.SelectedTab.ToString()

                Me.SavePatientHistory()
                'btnRefresh_Click(sender, e)
                TreeView2.CollapseAll()

                TreeView2.SelectedNode = N 'GV_SELECTED_EVENTID
                TreeView2.Focus()
            End If
        Else
            MsgBox("There are no events selected. Please create an event first.")
        End If

    End Sub

    Private Sub btnEventSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEventSave.Click
        'validate so that when save is clicked, check the treeview to see if there are any rows, if no display error message and do not save
        If treeviewhasrows() = True Then
            Dim N As TreeNode
            N = TreeView2.SelectedNode

            currentselectedtab = TabControl1.SelectedTab.ToString()

            Me.SavePatientEvent()
            btnRefresh_Click(sender, e)
            TreeView2.CollapseAll()
            'Me.Show()
            'Me.Refresh()
            TreeView2.SelectedNode = N 'GV_SELECTED_EVENTID
            TreeView2.Focus()

        Else
            MsgBox("There are no events selected. Please create an event first.")
        End If

    End Sub

    Private Function treeviewhasrows() As Boolean
        If (TreeView2.Nodes.Count = 0) Then
            treeviewhasrows = False
        Else
            treeviewhasrows = True
        End If

    End Function

    Private Sub TreeView2_DoubleClick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TreeView2.DoubleClick
        btnRefresh_Click(sender, e)
        TreeView2.CollapseAll()
        'TreeView2.Focus()
        Me.Focus()
    End Sub

    Private Sub Button5_Click(sender As System.Object, e As System.EventArgs)

    End Sub

    Private Sub Button5_Click_1(sender As System.Object, e As System.EventArgs) Handles Button5.Click
        Dim table As New DataTable()
        Dim CNnWind As New SqlClient.SqlConnection(GV_CONNETION)
        table = Me.recurrenceBindingSource1

        ' Create the InsertCommand.
        Dim command As SqlCommand = New SqlCommand(
            "INSERT INTO recurrence (recurrence_ID, Event_ID) " +
            "VALUES (@recurrence_ID, @Event_ID)", CNnWind)

        ' Add the parameters for the InsertCommand.
        command.Parameters.Add("@recurrence_ID", SqlDbType.NChar, 5, "recurrence_ID")
        command.Parameters.Add("@Event_ID", SqlDbType.NVarChar, 40, "Event_ID")

        Me.recurrenceDataAdapter.InsertCommand = command




        ' Create the UpdateCommand.
        command = New SqlCommand(
        "UPDATE recurrence SET recurrence_ID = '3' " +
        "WHERE recurrence_ID = 1", CNnWind)
        command.Parameters.Add("@recurrence_ID", SqlDbType.NChar, 5, "recurrence_ID")
        command.Parameters.Add("@Event_ID", SqlDbType.NVarChar, 40, "Event_ID")
        Dim parameter As SqlParameter = command.Parameters.Add("@oldCustomerID", SqlDbType.NChar, 5, "recurrence_ID")
        parameter.SourceVersion = DataRowVersion.Original

        Me.recurrenceDataAdapter.UpdateCommand = command

        Me.recurrenceDataAdapter.Update(table)
        MsgBox("Follow up Details Updated!")
    End Sub
End Class